# Number\_to\_currency

**URL:** <https://www.ruby-forum.com/t/number-to-currency/122304>\
**Category:** Rails\
**Created:** [December 6, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/number-to-currency/122304 "2007-12-06T12:45:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [December 6, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/number-to-currency/122304/1 "2007-12-06T12:45:36Z")

</div>

I am using the number to currency function because i live in the uk and  
the company want me to only show values of the pound of course.I have  
created all my application using ruby script/generate  
scaffold\_resource… I have come across with a problem… this code is  
in my applcation:

def number\_to\_currency(number, options = {})  
options = options.stringify\_keys  
precision, unit, separator, delimiter = options.delete(“precision”) {  
2  
}, options.delete(“unit”) { “Â£” }, options.delete(“separator”) { “.” },  
options.delete(“delimiter”) { “,” }  
separator = “” unless precision \> 0  
begin  
parts = number\_with\_precision(number, precision).split(’.’)  
unit + number\_with\_delimiter(parts[0], delimiter) + separator +  
parts[1].to\_s  
rescue  
number  
end  
end

it definately should work, but why doesnt the Â£ sign come as a question  
mark I have also tryed:

def number\_to\_currency\_gbp (number)  
number\_to\_currency(number, { :unit =\> “£”})  
end

This doesnt work either it is not picking up the &pound how can i solve  
this problem thanks

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [December 6, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/number-to-currency/122304/2 "2007-12-06T16:25:55Z")

</div>

this works for me…

\<%= number\_to\_currency(12.65, :unit =\> “£”) %\>  
returns =\> £12.65

does that help?

On Dec 6, 6:45 am, Nish P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [December 6, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/number-to-currency/122304/3 "2007-12-06T16:27:41Z")

</div>

crap, Google converted it for me. I meant this (take out the  
'_remove_’s):  
\<%= number\_to\_currency(12.65, :unit =\> “&_remove\_pound\_remove_;”)  
%\>

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [December 6, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/number-to-currency/122304/4 "2007-12-06T17:38:07Z")

</div>

hi thanks for that i have tried this and it does work, but what if i was  
using active scaffold? how do i get around this as it compeltely ignores  
it
