Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round down to full hundred [duplicate]

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

like image 620
user1735856 Avatar asked Dec 07 '22 03:12

user1735856


2 Answers

Use Math.floor.

Math.floor - Round a number downward to its nearest integer:

var berechungsgrundlage_gerundet = Math.floor(berechnungsgrundlage / 100) * 100;   
like image 137
ragklaat Avatar answered Dec 26 '22 04:12

ragklaat


You can use Math.floor:

Math.floor(number / 100) * 100;

Demo

like image 38
Milind Anantwar Avatar answered Dec 26 '22 04:12

Milind Anantwar