0

I need to round a result number,by precision;

Example:
Math : y=x/1000000; x=5 => y=0.000005,
but if I do this in java script y=0.00000500001;(not right) ;how do I round a equation by precision to have a math result

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

One way is that you can convert the result to a string object and do a substring to extract the portion of the result desired.

var a = 0.000050001;
var precision = 5;
var strA = a.toString();
var result = strA.substr(0, precision + 2);
alert(result);

I am not saying this is the only efficient way of doing it, but yes, one way of doing it.

0

Yes it is a option.
I have this code:

[
f = Math.pow((i+1),m)-1;
f /= den;
f *= document.calform.total_invested.value;
d = String(f).indexOf(".");
s = String(f).substring(0,(d+3));
document.calform.total.value = "$" + s;

the problem is if the document.calform.total_invested.value; is bigger then 100000000 the code is not working , it gives me
random results.

0

Look carefully the code I had posted and make the changes in your code accordingly. You are getting th formula and the method all wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.