Skip to content

Instantly share code, notes, and snippets.

@syedsaqibali
Created July 23, 2014 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syedsaqibali/625742da4ec0a64584ed to your computer and use it in GitHub Desktop.
Save syedsaqibali/625742da4ec0a64584ed to your computer and use it in GitHub Desktop.
irb(main):002:0> require 'bigdecimal'
=> true
irb(main):003:0> v = BigDecimal("7.1762")
=> #<BigDecimal:7f8905213dc0,'0.71762E1',18(18)>
irb(main):004:0> v.truncate(2).to_s('F')
=> "7.17"
irb(main):005:0> w = BigDecimal("4.2")
=> #<BigDecimal:7f890522c5f0,'0.42E1',18(18)>
irb(main):006:0> w.truncate(2).to_s('F')
=> "4.2"
irb(main):007:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment