round(argument)

Tinderbox Icon


Operator Type:   Function
Operator Scope of Action:   Item
Operator Purpose:   Mathematical

round(argument)

round() rounds the value of its argument to the nearest integer.

The Number.format, Number.precision and format() functions all round numbers in this manner when shortening numbers during formatting. A partial integer over .50 always round up, everything else rounds down. Thus:

$MyNumber = round(4.0) gives 4

$MyNumber = round(4.2) gives 4

$MyNumber = round(4.5) gives 5

$MyNumber = round(4.7) gives 5

The round function with work on string litteral or String attribute values that are just numbers:

$MyNumber = round("4.2") gives 4

$MyNumber = round("4.7") gives 5

$MyString = round(4.2) gives "4"

$MyString = round(4.7) gives "5"

$MyString = round("4.2") gives "4"

$MyString = round("4.7") gives "5"

There are no functions to always force a round down (floor) or up (ceiling), but these can be simulated with a bit of action code.

To always round down:

if($MyNum > 0){
$MyNumA = round($MyNum-0.5);
}else{
$MyNumA = round($MyNum+0.5);
}

And the reverse? To alway round a number up:

if($MyNum > 0){
$MyNumA = round($MyNum+0.5);
}else{
$MyNumA = round($MyNum-0.5);
}

In both the above, negative numbers move towards/away from zero in the same fashion as positive ones. Adjust the code for other types of rounding.


Possible relevant notes (via "Similar Notes" feature):

Up: Mathematical operators

A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Types : Mathematical operators : round(argument)

Quicklinks: Attributes | Action Codes | Export Codes | Designators | Date Formats | aTbRef Site Map

[Last updated: 21 May 2012, using v5.11.1]


Search:

Google search aTbRef for:  


Creative Commons Licence

aTbRef by Mark Anderson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

[See aTbRef CC licence Attribution & Waiver info]

Made with Tinderbox