General Question

dookie's avatar

What's the equivalent to PHP's number_format method in Ruby?

Asked by dookie (61points) June 19th, 2008
2 responses
“Great Question” (0points)

PHP’s number_format method converts 1234 to 1,234 (adding the comma). In Ruby, it would need to be a method on an Fixnum (or a Float) that would return a String.

Observing members: 0
Composing members: 0

Answers

sferik's avatar

In Rails, you can use the format method. For example:

>> 1234.format
=> "1,234"
sferik's avatar

The format method is deprecated in Rails 2.1.

It is replaced by the number_with_delimiter method.

Answer this question

Login

or

Join

to answer.

Mobile | Desktop


Send Feedback   

`