2
I need to get a cash amount and I’m only getting one house after the comma. example 75.50 I get 7.5 and 7 I need to receive 7.00;
I am using Jquery;
2
I need to get a cash amount and I’m only getting one house after the comma. example 75.50 I get 7.5 and 7 I need to receive 7.00;
I am using Jquery;
5
You can use the .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 decimals after the point is higher than the reported one, round the value by being [0...4] rounded down and [5...9] rounded up.
I added a note on when the value exceeds the value of decimals, I do not know if it became good rs, but I found it interesting to add, in case you want to change or reverse is no problem :)
@Marceloboni great, thank you!
Thank you! @Sergio
1
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 right of the decimal point) must be displayed.
var num = 7;
var result = num.toPrecision(3);
document.write (result);
0
Use this jQuery Mask plugin to mask all kinds.
Thanks for the comment friend, I used jquery Mask in another project, but this was not possible, because in the input (input) were integers and in the calculation there were real numbers, often the result is a real number.
Browser other questions tagged javascript jquery input
You are not signed in. Login or sign up in order to post.
How do you "receive"? From a query? From the form?
– BrTkCa