Game Development Community

Decimal point format operator as in C printf?

by Rob Segal · in Torque Game Builder · 07/18/2006 (10:17 pm) · 2 replies

Is there a format operator in torque script where I can cut the number of decimal points displayed on a floating point number like in C...

float x = 2.345345345345345;
printf("%.2f", x);

So the above example would print 2.34.

#1
07/19/2006 (4:15 am)
Copied and pasted from TDN:

mFloatLength( val , numDecimals )

Purpose
Use the mFloatLength function to limit the number of decimal places in val to numDecimals.

Syntax
val - A floating-point value.
numDecimals - An integer between 0 and inf representing the number of decimal places to allow val to have.

Returns
Returns a floating-point value equivalent to a truncated version of val, where the new version has numDecimals decimal places.
#2
07/19/2006 (8:13 am)
Yeh that's the ticket. Thanks Thomas!