2015-08-02 12:12:44 +00:00
|
|
|
The '''FIX''' function rounds a numerical value to the next whole number closest to zero.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2016-03-18 11:36:04 +00:00
|
|
|
:: result = '''FIX('''''expression''''')'''
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2016-03-18 11:36:04 +00:00
|
|
|
{{Parameters}}
|
|
|
|
* The ''expression'' is any [[TYPE]] of literal or variable numerical value or mathematical calculation.
|
|
|
|
|
|
|
|
|
|
|
|
{{PageDescription}}
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[FIX]] effectively truncates (removes) the fractional part of ''expression'', returning the integer part.
|
|
|
|
* This means that [[FIX]] rounds down for positive values and up for negative values.
|
2016-03-18 11:36:04 +00:00
|
|
|
* Use [[INT]] to round down negative values. Positive values are rounded down by both.
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
''Example 1:'' Showing the behavior of [[FIX]] with positive and negative decimal point values.
|
|
|
|
{{CodeStart}} '' ''
|
|
|
|
PRINT FIX(2.5)
|
|
|
|
PRINT FIX(-2.5) '' ''
|
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}2
|
|
|
|
-2
|
|
|
|
{{OutputEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
''Example 2:'' The NORMAL arithmetic method (round half up) can be achieved using the function in the example code below:
|
|
|
|
{{CodeStart}} '' ''
|
|
|
|
{{Cl|PRINT}} MATHROUND(0.5)
|
|
|
|
{{Cl|PRINT}} MATHROUND(1.5)
|
|
|
|
{{Cl|PRINT}} MATHROUND(2.5)
|
|
|
|
{{Cl|PRINT}} MATHROUND(3.5)
|
|
|
|
{{Cl|PRINT}} MATHROUND(4.5)
|
|
|
|
{{Cl|PRINT}} MATHROUND(5.5)
|
|
|
|
|
|
|
|
{{Cl|FUNCTION}} MATHROUND(n)
|
|
|
|
MATHROUND = {{Cl|FIX}}(n + 0.5 * {{Cl|SGN}}(n))
|
|
|
|
{{Cl|END FUNCTION}} '' ''
|
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
{{OutputEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
''See also:''
|
2016-03-18 11:36:04 +00:00
|
|
|
* [[INT]], [[CINT]]
|
|
|
|
* [[CLNG]], [[_ROUND]]
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[MOD]], [[\|Integer Division]]
|
|
|
|
* [[/|Normal division]]
|
|
|
|
|
2016-03-18 11:36:04 +00:00
|
|
|
|
2015-08-02 12:12:44 +00:00
|
|
|
{{PageNavigation}}
|