float to a decimal number


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.