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...
Printable View
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...
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?
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.
Code:class decimal{
public static void main(String[] args){
double d = 34.42;
int i = (int)d;
System.out.println(d);
System.out.println(i);
}
}
Yep that would work, I didnt know if he wanted to round just at the decimal though or to a specified significant digit.