Hi there I want to round down an amount to full hundred: Examples 23009 rounded 23000, 23099 rounded 23000, 23199 rounded 23100,
My function do not work, because it rounds mathematically.
$("#span_berechnungsgrundlage").text(berechnungsgrundlage);
var berechungsgrundlage_gerundet = Math.round(berechnungsgrundlage / 100) * 100;
alert(berechungsgrundlage_gerundet);
Thank you for your help
Use Math.floor
.
Math.floor
- Round a number downward to its nearest integer:
var berechungsgrundlage_gerundet = Math.floor(berechnungsgrundlage / 100) * 100;
You can use Math.floor
:
Math.floor(number / 100) * 100;
Demo
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