ScriptSpot

Forum topic · General Scripting

printing out float values to a few decimal points

By Guessmyname · 2011-06-24

Description

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 (3)

robertjacke · 2012-09-10

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.

formattedPrint

Anubis · 2011-06-25

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"

Guessmyname · 2011-06-24

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
)