Difference between revisions of "Round"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
m
imported>Eliteofdelete
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Math and Numbers|
 
  
 
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.|
  
needscode=yes|
+
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

int round(float number )

  • 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