Created
January 21, 2015 04:03
-
-
Save paladini/b92a3ba6899ef3b1b172 to your computer and use it in GitHub Desktop.
This method truncates a float or double number in Ruby programming language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This method truncate a float / double number. | |
def truncate(number, decimalCases = 2) | |
temp = 1.0 | |
while decimalCases > 0 do | |
temp = temp * 10.0 | |
decimalCases -= 1 | |
end | |
return (number * temp.to_i).floor / temp | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment