format a float number with specific number of decimal point

O

Oscar Lok

Hi,
May I know that how to format a float number with specific number of
decimal point, please?
e.g :--
123.456789 to 123.4568
123.123321 to 123.1233

Thanks
Regards
Oscar
 
D

David Kastrup

Oscar Lok said:
Hi,
May I know that how to format a float number with specific number of
decimal point, please?
e.g :--
123.456789 to 123.4568
123.123321 to 123.1233

irb(main):039:0> print [123.456789, 123.123321].collect {|x| format("#{x} to %.4f\n",x)}
123.456789 to 123.4568
123.123321 to 123.1233
=> nil
irb(main):040:0>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top