decide the number o decimal houses in a decimal number

hi,I want to print a double but if I use toString i'm not able to do what I want that is something like this in c language:printf("%2f",var);which is if I have 1,42352424554 I want to print just 1.42.how can I do that?Thanks
[292 byte] By [Ricardo_EI_ESTGa] at [2007-11-26 13:11:38]
# 1
Have a look at the DecimalFormat class or read all about the printf method available in Java 1.5 or later.kind regards,Josps. I like the phrase 'decimal houses'.
JosAHa at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...
# 2
You can also use String.format() method in 1.5 and up~Tim
SomeoneElsea at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...
# 3
the "decimal houses" expressions is because I don't remember how to say it in english and so I used the portugueses expression that is "casas decimais" Thanks
Ricardo_EI_ESTGa at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...
# 4

> the "decimal houses" expressions is because I don't

> remember how to say it in english and so I used the

> portugueses expression that is "casas decimais"

No hard feelings; I simply liked the "decimal houses" phrase; and more

important: I understood it ;-)

> Thanks

You're welcome of course.

kind regards,

Jos

JosAHa at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...
# 5
> the "decimal houses" expressions is because I don't> remember how to say it in english and so I used the> portugueses expression that is "casas decimais" > > ThanksDecimal places.
Mr_Evila at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...
# 6

> I want to print a double but if I use toString i'm

> not able to do what I want that is something like

> this in c language:

> printf("%2f",var);

>

> which is if I have 1,42352424554 I want to print just

> 1.42

Very similar to the C approach -

double v = 1.42352424554;

System.out.printf("%1.2f", v);

Check the Javadoc of Formatter for details of this.

sabre150a at 2007-7-7 17:27:28 > top of Java-index,Java Essentials,New To Java...