Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping decimal point

Tags:

ruby

I need to compare a data set in which one batch of data came with currency with decimals such as 246.54 the new data removes the decimals, does not round up, and has just 246... so I need to remove the decimals from the first batch so I can compare. How would I do this without rounding up?

like image 340
user1563849 Avatar asked Sep 28 '12 19:09

user1563849


2 Answers

Use the floor function. It gives the first integer smaller than or equal to whatever number you feed it.

1.9.3-p194 :003 > i = 246.54
  => 246.54 
1.9.3-p194 :004 > i.floor
  => 246 
like image 91
Qsario Avatar answered Oct 16 '22 21:10

Qsario


if mynumber >= 0 then 
    mynumber = mynumber.floor
else
    mynumber = 0 - mynumber
    mynumber = mynumber.floor
    mynumber = 0 - mynumber
end
like image 1
Keir Finlow-Bates Avatar answered Oct 16 '22 20:10

Keir Finlow-Bates