PDA

Click to See Complete Forum and Search --> : Please Help!!!!


Evil_Ryu
Jul 9th, 2002, 09:06 AM
I need a function that take away the decimal from a number... a function that do this...

the number:

12,34555555


the result:

12,3

Can i do this with a javascript function or i have to do it by myself??


Any idea would be useful... thanks...

billrogers
Aug 27th, 2002, 04:21 PM
Ack number one this is a java forum, not a javascript forum, number two I believe that you miswrote you example. If you want a function to take away the decimal, how do you go from 12.3455555 to 12.3 Do you want significant digits or do you want to convert a float to an int?

Dillinger4
Aug 27th, 2002, 11:03 PM
Do you mean 12,34555555 as 12.34555555? I think that is what you ment. ;) Yes as billrogers pointed out you would be better asking this in the java script forum. If you were doing this in java then you could cast the double value to an int to lose the precision.

class decimal{
public static void main(String[] args){
double d = 34.42;
int i = (int)d;
System.out.println(d);
System.out.println(i);
}
}

billrogers
Aug 29th, 2002, 02:43 PM
Yep that would work, I didnt know if he wanted to round just at the decimal though or to a specified significant digit.