Format a float number with specific number of decimal point

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

Oscar L. [email protected] writes:

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>