Displaying trailing zero for a float variable !!

J

Jagster

Hi,

I have a variable in database which is float and when i display it on
browser i need to display the trailing zero i.e say the value is 5.6 it
should show as 5.60 to maintain uniform way of displaying as 5.65 is
displayed as 5.65. any ideas what would be the best way to achieve this ??

thanx
Jag
 
T

Thomas G. Marshall

Jagster coughed up:
Hi,

I have a variable in database which is float and when i display it on
browser i need to display the trailing zero i.e say the value is 5.6
it should show as 5.60 to maintain uniform way of displaying as 5.65
is displayed as 5.65. any ideas what would be the best way to achieve
this ??

thanx
Jag


java.text.NumberFormat. Learn it, live it, love it.

Use it's format() for all output and its parse() for all input. This will
allow your numbers to be seamlessly output and be input with separation
commas (in the states):

1,000,000.00

And in reverse for Europe:

1.000.000,00

And in whatever whackjob way the current locale of a country might need it.

And there's a method in there for setting the number of fractional digits.



--
Iamamanofconstantsorrow,I'veseentroubleallmydays.Ibidfarewelltoold
Kentucky,TheplacewhereIwasbornandraised.ForsixlongyearsI'vebeenin
trouble,NopleasureshereonearthIfound.ForinthisworldI'mboundtoramble,
Ihavenofriendstohelpmenow....MaybeyourfriendsthinkI'mjustastrangerMyface,
you'llneverseenomore.ButthereisonepromisethatisgivenI'llmeetyouonGod's
goldenshore.
 
A

Alex Kizub

java.text.NumberFormat f;
f = java.text.NumberFormat.getInstance();
f.setMaximumFractionDigits(2);
f.setMinimumFractionDigits(2);
System.out.println(f.format(5.65)+" "+f.format(5.6));
I have a variable in database which is float and when i display it on
browser i need to display the trailing zero i.e say the value is 5.6 it
should show as 5.60 to maintain uniform way of displaying as 5.65 is
displayed as 5.65. any ideas what would be the best way to achieve this ??

Alex Kizub.
 
D

Dave Monroe

Jagster said:
Hi,

I have a variable in database which is float and when i display it on
browser i need to display the trailing zero i.e say the value is 5.6 it
should show as 5.60 to maintain uniform way of displaying as 5.65 is
displayed as 5.65. any ideas what would be the best way to achieve this ??

thanx
Jag

Look up the DecimalFormat class. Very flexible, very useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top