Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.




Introduced in

Version:1.21

Description

Description:Rounds a number to the given amount of decimal places.

Syntax

Syntax:[number,digits,pad] call fn_vbs_cutDecimals
Parameters:
be formatted. (Nested arrays will not work!)
  • format (the function does do not work for nested arrays).
  • digits: Number - Number of decimal digits to keep
.
  • (optional, default
=
  • : 2).
  • pad: Boolean - Pad decimal digits to always return the specified number of digits. If this option is active, the number is returned as a string (optional, default: false). (V1.30
or higher
  • +)
Return Value:(Number or Array), or (String, if pad
option
is set to true).

Warning

When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.

Examples

Examples:
[1.2345, 2]
 call fn_vbs_cutDecimals; // 
returns
Returns 1.23
[[1.234,2.345,3.456]] call fn_vbs_cutDecimals;   // 
returns
Returns [1.23,2.35,3.46]
[[1.234,2.345,3.456],2] call fn_vbs_cutDecimals; // 
returns
Returns [1.23,2.35,3.46]
[[1.234,2.345,3.456],1] call fn_vbs_cutDecimals; // 
returns
Returns [1.2,2.3,3.5]
[[1.234,2.345,3.456],0] call fn_vbs_cutDecimals; // 
returns
Returns [1,2,3] 
[[1,2.3,3.45,4.567],2, true] call fn_vbs_cutDecimals; // 
returns
Returns ["1.00","2.30","3.45","4.57"]
[[1,2.3,3.45,4.567],1, true] call fn_vbs_cutDecimals; // 
returns
Returns ["1.0","2.3","3.5","4.6"]
[[1,2.3,3.45,4.567],0, true] call fn_vbs_cutDecimals; // 
returns
Returns ["1","2","3","5"]

Additional Information

See also: round, ceil, floor, numToStr
Multiplayer: 
Problems: 

Notes