Small question!

Hi,

Why should I add casting for :

float[] array ={(float) 12.34, (float) 24.78, (float) 14.67};

I want a method to do this:

12.346 --> 12.34

Please, with example

[387 byte] By [MoonSpotLighta] at [2007-11-26 17:28:33]
# 1
a) Java cosiders all floating point numbers to be double. You don't need to cast, if you just append a f to the number:float f = 12.11f;b) look at NumberFormat.
PhHeina at 2007-7-8 23:56:30 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hi,

>

> Why should I add casting for :

>

> float[] array = {(float) 12.34, (float) 24.78,

> (float) 14.67};

>

> I want a method to do this:

>

> 12.346 --> 12.34

>

> Please, with example

Because 12.34 is a double.

12.34f is a float

> 12.346 --> 12.34

Check out DecimalFormat

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html

manuel.leiriaa at 2007-7-8 23:56:30 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks
MoonSpotLighta at 2007-7-8 23:56:30 > top of Java-index,Java Essentials,Java Programming...