A Conversation for The H2G2 Programmers' Corner
Java NumberFormat
Researcher PSG Started conversation Sep 23, 2003
Hello
I'm a bit new to Java and I was just wondering if there was a way to use NumberFormatter to format a text field to a float number.
Any help appreciated
Researcher PSG
Java NumberFormat
Calculator Nerd 256 Posted Sep 25, 2003
i think it is called parseFloat(String);
i'm new to java, so i understand how annoying it is to learn new standards
must...perfect...anaglyph...class
if u haven't guessed, i'm having some trouble as well
if you need a huge database, try java.sun.com and somewhere on there is a really cool page full of classes and their methods and stuff
it's nice, but it won't tell you how to make your classes work right
(perhaps i'll start a thread about my anaglyph problem)
>8^B
Java NumberFormat
Calculator Nerd 256 Posted Oct 5, 2003
o
nm
i think i misunderstood u
u meant how to out a float
DecimalFormat myDecimalFormat = new DecimalFormat("0000.00");
System.out.println(myDecimalFormat.output(201.765));
that would make an output of "0201.77"
i think i got some of the words wrong, but that is basically how a DecimalFormat works
try it to make sure i am right before going and writing a big program with that in it
>8^B
Java NumberFormat
Researcher PSG Posted Oct 6, 2003
Thanks Calc
I had found the DecimalFormat thing by accident a week or so ago, and I apologise for not posting it. But hopefully others will find it useful.
Why they couldn't have just had a float format thing though? oh well
Researcher PSG
Java NumberFormat
Calculator Nerd 256 Posted Oct 7, 2003
lol yeah
o i neglected to mention that u need this line at the beginning:
import java.text.DecimalFormat
now let's hope i can remember that by test time
>8^B
Java NumberFormat
Calculator Nerd 256 Posted Oct 7, 2003
oops again
(is there an tag? guess i'll find out when i post)
i put
DecimalFormat.output(float);
it should be
DecimalFormat.format(float);
maybe next time i'll just link to the javadoc
>8^B
Key: Complain about this post
Java NumberFormat
More Conversations for The H2G2 Programmers' Corner
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."