Last updated 1998 June 16 by Roedy Green ©1996-1998 Canadian Mind Products.
Stuck in a frame? Click here to break out.// get an conversion object customised for a particular locale java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); // set whether you want commas (or locale equivalent) inserted nf.setGroupingUsed(true); // set how many places you want to the right of the decimal. nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); // set how many places you want to the left of the decimal. nf.setMinimumIntegerDigits(1); nf.setMaximumIntegerDigits(10); // convert from binary to String String s1 = nf.format(1234L); // will produce 1,234.000 not 1.234 !! String s2 = nf.format(1.234D); // will produce 1.234 // convert from String to binary Number n1 = null; Number n2 = null; try { n1 = nf.parse("1,234"); // will produce a Long 1234L n2 = nf.parse("1.234"); // will produce a Double 1.234D } catch (java.text.ParseException e) {}
![]() |
![]() |
![]() |
|
Canadian Mind Products | The Mining Company's Focus on Java Best of the Net Award |
You can get an updated copy of this page from http://mindprod.com/jglossn.html |