Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:32:43+00:00 2026-05-17T23:32:43+00:00

So I’m writing what I thought was a simple .rb file to convert a

  • 0

So I’m writing what I thought was a simple .rb file to convert a float number into a string. The string returns my floating point number in words. So if I have 11.11 then I would have eleven dollars and eleven cents So far I’ve extended the float class which has worked alright. I’m having trouble with how to convert the 11 cents into eleven cents. en.numwords would kick back eleven point one one. I’ve thought about trying out a hash to solve my problem where 11=>eleven cents. Any thoughts how I could implement this? Perhaps a better way to implement this?

Here’s what I have so far:

 require 'rubygems'
 require 'linguistics'
 Linguistics::use( :en )



 class Float
 def to_test_string
 puts self #check
 puts self.en.numwords
 self.en.numwords
 end

 end

 puts "Enter two great floating point numbers for adding"
 puts "First number"
 c = gets.to_f
 puts "Second number" 
 d = gets.to_f
 e = c+d
 # puts e
 puts e.to_test_string
 puts "Enter a great floating number! Example 10.34"
 a = gets.to_f
 # puts a
 puts a.to_test_string

Thanks for the help! Post some code so I can try ideas out!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:32:43+00:00Added an answer on May 17, 2026 at 11:32 pm

    This problem can be solved by splitting the float into two values: dollars and cents.

    require 'rubygems'
    require 'linguistics'
    Linguistics::use( :en )
    
    class Float
        def to_test_string
            puts self #check
    
            #Split into dollars and cents
            cents = self % 1
            dollars = self - cents
            cents = cents * 100
    
            text = "#{dollars.to_i.en.numwords} dollars and #{cents.to_i.en.numwords} cents"
    
            puts text
            text
        end
    end
    
    puts "Enter two great floating point numbers for adding"
    puts "First number"
    c = gets.to_f
    puts "Second number" 
    d = gets.to_f
    e = c+d
    # puts e
    puts e.to_test_string
    puts "Enter a great floating number! Example 10.34"
    a = gets.to_f
    # puts a
    puts a.to_test_string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.