Round: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Bale
mNo edit summary
imported>Eliteofdelete
No edit summary
 
Line 17: 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]]
[[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