I am looking for an efficient way to cut floating number at Javascript which are long. I need this because my output for taking percentage of two numbers can be sometimes like 99.4444444 while I am only interested in the first 2 digits after "." such as 99.44
My current percentage taking function for 2 numbers:
function takePercentage(x,y){
return (x /y) * 100;
}
You can use number.toFixed:
function takePercentage(x,y){
return ((x /y) * 100).toFixed(2);
}
How about this:
Math.round( myfloatvalue*100 ) / 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With