#1803 Formatting Floats

SlimerDude Sat 3 Mar 2012

Hi,

Is there a simple way to format a Float into an X decimal place Str? I'm thinking of something similar to Java's:

String.format("%.2f", floatValue)

Cheers.

ttmrichter Sat 3 Mar 2012

You probably want to look at:

For the latter you'll also have to look at the following:

Between these you can emulate most of String.format.

λ ~ → fansh
Fantom Shell v1.0.62 ('?' for help)
fansh> 12345.6789f.toLocale("0.00")
12345.68
fansh> 12345.6789f.toLocale("0.00").padl(10,'0')
0012345.68

SlimerDude Sat 3 Mar 2012

Awesome! I skipped over sys::Float#toLocale thinking it was just boring I18N stuff!

Login or Signup to reply.