I need to receive a cash value and am only getting a house after the comma. example 75.50 I get 7.5 and 7 I need to receive 7.00;
I'm using Jquery;
I need to receive a cash value and am only getting a house after the comma. example 75.50 I get 7.5 and 7 I need to receive 7.00;
I'm using Jquery;
You can use .toFixed()
, a method of numbers, which does two things:
console.log((7.5).toFixed(2)); // dá 7.50
console.log((7).toFixed(2)); // dá 7.00
console.log((7.204).toFixed(2)); // dá 7.20
Note : If the number of decimal places after the point is greater than that reported, round the value, with [0 ... 4] being rounded down and [5 ... 9] rounded up.
One way is by using the toPrecision method, which allows you to define how many digits in total (including the digits to the left and to the right of the decimal point) should be displayed.
var num = 7;
var result = num.toPrecision(3);
document.write (result);
Use this jQuery Mask plugin to mask all types.