General Question

dookie's avatar

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

Asked by dookie (64points) June 19th, 2008

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

2 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.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther