Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

String#to_d

str.to_d → bigdecimal

Returns the result of interpreting leading characters in str as a BigDecimal.

Example
require 'bigdecimal'
require 'bigdecimal/util'

"0.5".to_d             # => 0.5e0
"123.45e1".to_d        # => 0.12345e4
"45.67 degrees".to_d   # => 0.4567e2

See also Kernel.BigDecimal.

See also #to_c #toeuc #swapcase! #to_f also in 3.2 · 3.1 · 3.0