| | |
Custom NumberFormat
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
•
•
I want to create a custom NumberFormat which returns empty string for negative values and the double number iteslf for +ve and zero values. Please guide me....................
This is for you.
java Syntax (Toggle Plain Text)
public class CustomNumberType extends Number{ public double doubleValue() { return 0; } public float floatValue() { return 0; } public int intValue() { return 0; } public long longValue() { return 0; } }
Implement your logic in this class.
Regards,
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
•
•
Join Date: Aug 2009
Posts: 39
Reputation:
Solved Threads: 5
•
•
•
•
Hello,
This is for you.
java Syntax (Toggle Plain Text)
public class CustomNumberType extends Number{ public double doubleValue() { return 0; } public float floatValue() { return 0; } public int intValue() { return 0; } public long longValue() { return 0; } }
Implement your logic in this class.
Regards,
Wht I need in output is a object of class NumberFormat or ChoiceFormat which will have a label empty string for a -ve value and the number itself for +ve and zero values..................
•
•
•
•
I want to create a custom NumberFormat which returns empty string for negative values and the double number iteslf for +ve and zero values. Please guide me....................
Java Syntax (Toggle Plain Text)
if value is negative return "empty String" else return the value
You need to explain your problem better and show some code
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Aug 2009
Posts: 39
Reputation:
Solved Threads: 5
•
•
•
•
Then write a method that:
Java Syntax (Toggle Plain Text)
if value is negative return "empty String" else return the value
You need to explain your problem better and show some code
Java Syntax (Toggle Plain Text)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; class MyNumberFormat extends NumberFormat { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { if(number>=0) return toAppendTo.append(number); else return toAppendTo.append(""); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { if(number>=0) return toAppendTo.append(number); else return toAppendTo.append(""); } @Override public Number parse(String source, ParsePosition parsePosition) { throw new UnsupportedOperationException(); } }
![]() |
Similar Threads
- custom .htaccess file 301 Redirect to non www form (Search Engine Optimization)
- Internet Explorer Favorites, custom website icons disappearing (Web Browsers)
- Us Staffing-custom Application Engineer (Tech / IT Consultant Job Offers)
- Looking for a cheap custom vbulletin style (Web Development Job Offers)
- Security Settings -> Java permission -> Custom (radio button) -> Java Custom Settings (Web Browsers)
- Internet Security Keeps Resetting To Custom (HiJackThis Log) (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: java installation
- Next Thread: How to get Jar to be recognized command?
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads time tree unlimited webservices windows






