Everything about Software & security!
Pagina's
Home
JScrape - Java scraping
About me
vrijdag 8 april 2011
[Java] Format a Float @ 2 decimals precision
Here's a small code example of how you could format a float to be displayed at 2 decimals precision (only when necessary).
import java.text.NumberFormat;
...
NumberFormat
nf =
NumberFormat
.
getInstance
(
)
;
nf.
setMaximumFractionDigits
(
2
)
;
nf.
setMinimumFractionDigits
(
0
)
To actually format a float, one could simply do:
nf.
format
(
myFloat
);
It's as simple as that ;)
@Qkyrie
Geen opmerkingen:
Een reactie posten
Nieuwere post
Oudere post
Homepage
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten