Round: Difference between revisions
Jump to navigation
Jump to search
imported>StDoodle Created page with '{{ #vardefine:name|round}}{{ #vardefine:return_type|int}}{{ FunctionPage| name={{#var:name}}| function_category=| function1={{Function| name={{#var:name}}| aggregate={{#var:agg…' |
imported>Eliteofdelete No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
FunctionPage| | FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 18: | Line 17: | ||
function_description=Rounds {{pspan|number}} to the nearest whole number, and returns the result.| | function_description=Rounds {{pspan|number}} to the nearest whole number, and returns the result.| | ||
code1={{CodeSample| | |||
title=Code Samples| | |||
description=Rounds numbers to the place desired.| | |||
code= | |||
<syntaxhighlight> | |||
float rounder (float number, int place) { | |||
float value = round(number*10.0**-place)*10.0**place; | |||
print(value); | |||
return value; | |||
} | |||
rounder(35.5555, -2); | |||
rounder(25.5, 0); | |||
rounder(5256, 2); | |||
</syntaxhighlight>| | |||
moreinfo= | |||
<pre> | |||
35.56 | |||
26.0 | |||
5300.0 | |||
</pre> | |||
}}| | |||
}} | }} | ||
[[Category:Math and Numbers]] |
Latest revision as of 23:26, 21 January 2015
Function Syntax
- number is the number to round
Rounds number to the nearest whole number, and returns the result.
Code Samples
Rounds numbers to the place desired.
float rounder (float number, int place) {
float value = round(number*10.0**-place)*10.0**place;
print(value);
return value;
}
rounder(35.5555, -2);
rounder(25.5, 0);
rounder(5256, 2);
35.56 26.0 5300.0