I have some code
{{if commission}}
<td>${profit - commission}</td>
{{else}}
<td>${profit}</td>
{{/if}}
profit = 5
;
commission = 2.145
result = 2.855999999999
I need 2.856
Please help me
I try to use (${profit - commission}).toFixed(2)
- but it does not work.
To round off decimal values using jQuery, we can use the built-in JavaScript methods toFixed() or toPrecision(). The toFixed() method converts a number into a string, keeping a specified number of decimals. The toPrecision() method formats a number to a specified length.
Use the toFixed() method to round a number to 2 decimal places, e.g. const result = num. toFixed(2) . The toFixed method will round and format the number to 2 decimal places.
Or, if you want to round 0.2345 to two decimal places, you need to round 23.45 (0.2345*100), then divide the result (23) by 100 to get 0.23.
use javascript's Math. ceil() method to round numbers up. Save this answer.
Use simply toFixed(3)
.it will select the 3 digits value after the dot value
var s=2.855999999999;
alert(s.toFixed(3))
OP
: 2.856
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