top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the best way to convert a currency string 'USD' to locale :en-US?

+1 vote
494 views

What is the best way to convert a currency string 'USD' to locale :en-US? Right now trying to make it flexible to show the money and symbol correctly based on the currency string (like 'USD' or 'AUD') stored against the user's record.

I need to be able to do the following based on say 'GBP' string:

  :en-GB) %>
posted Sep 24, 2013 by Jai Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You could make a helper that would extract this value from the user and translate the display string. If you set up a hash like {'USD' => :en-US, 'GBP' => :en-BG, ...} then there would be one place to look for the correct symbol.

answer Sep 24, 2013 by Satish Mishra
Do you mean to convert USD 1000 into AUD 1000? Surely you would need to do a currency conversion because USD 1000 is AUD 1064. This would seem to have nothing to do with locales at all.
I just saw a gem on RubyFlow last week that handles currency conversions using Google as a data source. If that's what you're after, forget what I said and use that.
Similar Questions
+1 vote

I'm wonder how most people securely connect to a Postgres database on a server separate from the app server.

The ActiveRecord docs for a MySQL connection have explicit SSL options, whereas with Postgres it seems one would pass SSL options as documented for libpq.

However a quick Googling returns SO threads with suggestions to use SSH tunnels. Which I guess could be managed with something like AutoSSH.

I'd love to hear from others. Is one method faster than the other, or easier to maintain?

+1 vote

Does anybody know if there's anyway to upload a .xlsx file and then convert it to .xls file for later processing?

I'd like to use spreadsheet to write a new xls file but it doesn't support xlsx and the file is only importable with that format sadly. I saw roo but I don't know if there's a direct way to do it.

+2 votes

I am working on building an api client for the Rakuten Market-place. I have got some test requests for add delete update etc working and thought I should aim to structure it as a Gem and publish it so that others can use it/enhance it.

I haven't built a Gem before (worked mostly within the rails environment to date).

Have been reading and looking at other api client gems and am making progress on building something (still got a way to go to handle errors etc.)

To make the gem general purpose though, I am trying to figure out the best way to provide the mapping between models in a rails app and the api client objects (such as product, category, order etc).

I am aiming to make each client api object a class be (or should i call them models?)
Then I suspect I will use new to build an api instance from a rails instance, and find to return an api instance to a rails instance.

I can build in mapping for my own models to the api objects with no problem, but I can't see how I could generalize this so that other apps with similar models could use the gem.

I suspect there are approaches for doing this, but so far I haven't managed to come up with how to do it. If anyone has any wisdom on the matter I would be grateful.

+2 votes

I want to convert a string say "98989" into an integer without using any library functions in java. Give fastest way to do it and explain why your method is best.

+2 votes

I have a rails application, in which I am using delayed_job_active_record gem for running background jobs. While using the method .delay with an object, I am getting the following mysql error:

"INCORRECT STRING VALUE: \'XE2X9CX93"X0A ...\' FOR COLUMN \'HANDLER\' AT ROW 1"

I already searched for the above error and found that its because of the difference in encoding in mysql and rails. The solution suggested by many programmers is to alter the encoding in mysql database to utf8. But I also read that MySQL's utf8 charset only partially implements proper UTF-8 encoding. It can only store UTF-8-encoded symbols that consist of one to three bytes; encoded symbols that take up four bytes aren't supported. Which might cause trouble in some other cases. Also, when I tried to insert the value directly in mysql, it worked like a charm. Suggesting that the issue might lie elsewhere. So, can anyone please suggest the right method to rectify this problem?

Any help would be greatly appreciated.

...