Skip to content

Ruby Fleebie

Rediscovering the joy of programming… since 2007!

  • Home
  • About me
  • About Ruby Fleebie
  • Hire my services

float

How To Strip Insignificant Zeros From a Float In Rails

February 2012    short & sweet

I had a float attribute in a Rails application and wanted to strip non-significant zeros when displaying it on a page. With the number_with_precision helper from ActionView, that’s a trivial thing:

number_with_precision(
  3.50,
  strip_insignificant_zeros: true,
  precision: 2
)
# => '3.5'
Posted in short & sweetTagged float, helpers, rails5 Comments

Recent Posts

  • Deploy your Rails applications like a pro with Dokku and DigitalOcean
  • Remain professional even after your death
  • Testing Rails applications in the life of a freelancer
  • Rails isn't trendy anymore. Hooray for Rails!
  • How to backup your postgres database on SpiderOak using Dokku

Recent Comments

  • Revathy Ram Sundar on Remain professional even after your death
  • Enums in Ruby - ExceptionsHub on Enumerations and Ruby
  • Serge Seletskyy on Check for nil and initialize on a single line
  • Juan Pablo Giuttari on Understanding class methods in ruby
  • Komrad on Remain professional even after your death

Archives

  • December 2018
  • April 2016
  • December 2015
  • September 2014
  • December 2012
  • April 2012
  • February 2012
  • May 2011
  • December 2010
  • November 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • September 2009
  • February 2009
  • October 2008
  • September 2008
  • August 2008
  • May 2008
  • April 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Categories

  • Easy reading
  • In depth
  • short & sweet
  • The path of the freelancer

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Proudly powered by WordPress | Theme: typefocus8 by Ajay Divakaran.