Trunc

Not available in this language yet.
Trunc( value, [precision] )
Trunc( value, [precision] )
Trunc( value, [precision] )
Not available in this language yet.
Trunc( value, [precision] )

Description

The Trunc function returns a number which is the nearest mathematic value less than or equal to the operand to the specified precision as a double value.

Parameters

Argument Type Definition and Requirements

value

Number

A number to be truncated with a specific precision.

precision

Number

Optional - Defines how many digits to the right or left of the decimal place should be returned. The default precision is 2 which returns up to the hundredths decimal places. A positive precision specifies digits to the right of the decimal point. A negative precision specifies digits to the left of the decimal point. A zero precision truncates the fractional part of the number.

Returns

A number with its precision modified.

Examples

The query below executes an array of independent truncation operations and returns the results in an array. The result array position matches the execution array position. The first operation takes the value 1234.5678 and by default truncates the value to 2 digits to the right of the decimal point. The result is 1234.56 which is in the top position of the result array. The second operation truncates the value 1234 to a precision of -2. This is two digits to the left of the decimal point, the hundreds position. The operations to the left of the decimal point are zero filled less than the specified precision. The result of 1200 is placed in the third position of the result array.

Not available in this language yet.
Not available in this language yet.
System.out.println(
        client.query( Arr(
                Trunc(Value(1234.5678)),
                Trunc(Value(1234), Value(-2)),
                Trunc(Value(1234.5678), Value(2)),
                Trunc(Value(1234.5678), Value(-2)),
                Trunc(Value(5678.1234), Value(3)),
                Trunc(Value(1234), Value(-3)),
                Trunc(Value(5678.1234), Value(-3))
        )).get());
[
  1234.56, 
  1200, 
  1234.56, 
  1200.0, 
  5678.123, 
  1000, 
  5000.0
]
Not available in this language yet.
Not available in this language yet.
Not available in this language yet.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!