Float to_s hack for easy sprintf'in

Category: Other - Tools & Utilities

Float Hacks:to_s override.I really hate using sprintf, mainly because i always have to go online and look up the syntax. I figured i could make that a little easier. Now you can print floats with different precision as easily as:4.123456.to_s(1) # => "4.1"4.123456.to_s(3) # => "4.12"4.123456.to_s(3) # => "4.123"4.123456.to_s(4) # => "4.1235" (Note the auto rounding from 4.123456)4.123456.to_s # => "4.123456" Date: 19 January, 2012


Easy Sprintfing - Float Hack - Ruby Snippets - Easy - Sprintfing - Float

Homepage: http://snippets.dzone.com/

Developer: snippets.dzone.com

License: Freeware

Operating System: All

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

Float Hacks:to_s override.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: Windows, Linux


Split an array of elements into a set of smaller arrays of equal size.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: All


Split a string into an array of roughly equal sized chunks based on a string or regular expression delimiter.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: All


Get the currently running method name in Ruby - how to get the running methos name in ruby.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: All


A replacement for Ruby's File.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: All


The following code will create a live search in your Ruby on Rails project using AJAX.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: All


Clone dev DB schema to test DB in Rails.

developer Developer: snipplr.com
license License: Freeware
operating systems Operating System: All


This simple class is used to show a random image from an array of image paths.

developer Developer: phpbuilder.com
license License: Freeware
operating systems Operating System: All


Memory management routines.

developer Developer: snippets.org
license License: Freeware
operating systems Operating System: All