| | |
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: 63
Reputation:
Solved Threads: 8
•
•
•
•
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: 63
Reputation:
Solved Threads: 8
•
•
•
•
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?
Views: 268 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arguments array arrays automation binary bluetooth bold byte c++ chat class classes client code component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle pong print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user web websites windows






