printing out float values to a few decimal points

Hello!

Does anyone know of a way to export floating point values to a set decimal place? In my case, around 3 decimal places would be fine, so 0.0001 would become 0, 1.5549 becomes 1.555 etc.

It's for an animation exporter that works by move commands (ie Move(body, x_axis, 40) and so on), but when I format my test animation to a script file I very often see things like -3.90266e-007, which is pretty much zero but not exactly intuitively so.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robertjacke's picture

A method of stamping custom

A method of stamping custom business cards printing, that graphic is thoroughly introduced through the primary actinic activity of light-weight with out pursuing improvement by means of chemical substances.

Anubis's picture

formattedPrint

The function formattedPrint is good for such tasks ;)

formattedPrint pi format:"#.3f" -- "3.142"
formattedPrint e format:"#.3f" -- "2.718"
formattedPrint 776.12345 format:"#.3f" -- "776.123"

my recent MAXScripts RSS (archive here)

Guessmyname's picture

Nevermind, made a function

Nevermind, made a function for it.

function roundFloat val dp --rounds a float to a set number of decimal places
(
a = val * (10^dp)
b = a as integer
a = b as float / (10^dp)
return a
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.