Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard float precision in Ruby

I want to discard float precision.

(4.43597).discard(3)   =>   4.435 (not 4.436)

I don't want to use round. How should I do it ? I can't find of a way.

like image 594
seapy Avatar asked Dec 05 '25 16:12

seapy


1 Answers

  1. multiply by 1000
  2. cast to int
  3. divide by 1000.0
like image 159
Daniel Hilgarth Avatar answered Dec 08 '25 06:12

Daniel Hilgarth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!