I need to transform a decimal fraction received as a string into its
reciprocal, also stored as a string.  I have come up with this but I
would like to know if there exists a better way to accomplish this
requirement.

      trate = xchg.xpath('cb:value').text
      scale = 10 ** (trate.length() -1 - (trate.index('.').to_i))
      value = trate.gsub(/\.|,| /,'').to_i
      trate = (1000000 * scale / value).to_s
      trate = trate.rjust(7,'0')
      trate = trate.insert(-7,'.')
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to