Choose where you’d like to start

truncate

Overview

The truncate function returns the input decimal truncated to the specified number of places to the left or right of the decimal point.

Return Type

Syntax

<variable> = <number>.truncate(<digits>);

where,

ParameterData typeDescription
<variable>DECIMALVariable that will hold the truncated value.
<number>DECIMALVariable that holds the input decimal value.
<digits>NUMBER

number of digits that need to be truncated.

Note:

  • If a positive value is supplied, this function will truncate the specified number of places to the right of the decimal point.
  • If zero is supplied, this function will discard the right side of the decimal point and return only the integer value
  • If a negative value is supplied, this function will truncate the specified number of places to the left of the decimal point. That is, it will discard the right side of the decimal point and fill the specified number of places to the left of the decimal point with zeros.

Examples

 number = 25.125432 ;
 info number.truncate(2); // returns 25.12
​
 number = 9789.852 ;
 info number.truncate(0); // returns 9789
​
 number = 9789.852 ;
 info number.truncate(-2); // returns 9700

Get Started Now

Execute