Skip to content

Instantly share code, notes, and snippets.

@francois-blanchard
Last active October 31, 2016 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francois-blanchard/3c14fd580132cfc10ca930869738a8c0 to your computer and use it in GitHub Desktop.
Save francois-blanchard/3c14fd580132cfc10ca930869738a8c0 to your computer and use it in GitHub Desktop.
[ruby] How to round float number when it's a whole number

[ruby] How to round float number when it's a whole number

# with non-integer result
>> half_days = 3
=> 3
>> days = half_days / 2.0
=> 1.5
>> format('%g', days)
=> 1.5

# with whole number result
>> half_days = 4
=> 4
>> days = half_days / 2.0
=> 2.0
>> format('%g', days)
=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment