In mathematics, situations often arise when the full accuracy of a number is not needed or may interfere due to the impossibility of determining. Such situations may arise when working, for example, with complex motion functions.
Rounding numbers to a certain sign is its replacement with a similar value with the addition of the last one with zeros at the end.
Natural fractions can be subjected to this operation to a different degree of accuracy: tens, hundreds, thousands, etc. Depending on the required degree of accuracy, it is necessary to replace with zeros the digit in the digit to which rounding is performed. Using simple examples, you can imagine this operation.
So, when rounding a number to tens, zero it is necessary to replace the digit in the category of unity. At the same time, when rounding to hundreds - it is necessary to replace the discharge of units and tens.
.
PHP
PHP -, WEB- , . .
PHP
PHP : round, ceil floor. . - , , . - .
Round() :
float round ( float value [, int precision] )
, . , , , .
:
$roun = round(3.8); // 4
$roun = round(3.15); // 3
$roun = round(5.5); // 6
$roun = round(8.499); // 8
$roun = round(2.46,1); // 2.5
$roun = round(3.7384,3);// 3.738
$roun = round(1939,-1); // 1940
$roun = round(2.5,1); // 2.5
$roun = round(1444,-2); // 1400
:
$roun = round(3.467,2); // 3.47
:
$roun = round (4.827); // 5
, ceil() :
float ceil ( float value )
, .
:
$cei = ceil(4.7); // 5
$cei = ceil(4.001); // 4
$cei = ceil(6.5); // 7
$cei = ceil(3.0); // 3
,
floor(), :
float floor ( float value )
, , .
:
$okr = floor(4.99); // 4
$okr = floor(5.023); // 5
$okr = floor(6.4); // 6
$okr = floor(7.0); // 7
JavaScript
JavaScript, PHP, . PHP , , , Math.
JavaScript . . Math. «.», . , .
:
alert('Math.floor(125.6768) = ' + Math.floor(125.6768));
125.
- JavaScript.