Posted By

gangbird on 09/30/07


float decimal

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


float to a decimal number

 / Published in: Ruby

  1. def f_to_dec(f, prec=2,sep='.')
  2. f.to_i.to_s+sep+((prec-(post=((f*(10**prec)).to_i%(10**prec)).to_s).size).times do post='0'+post end; post)
  3. end

Report this snippet  

You need to login to post a comment.