Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Fixnum to String

Fixnum to String Script

Okay, I admit this is really kinda useless, but I made a script that (badly) converts Intergers to Words. The reason I say badly is because, if you put in something like 1065 it come out as TenSixFive, instead of One Thousand Sixty-Five. But Anyway, I think someone could go far with this, but I just made it for my needs, so...

Code:
#==============================================================================
# ** Fixnum 
#------------------------------------------------------------------------------
#  ???
#==============================================================================
class Fixnum
  def to_word
    if self == 1
      return "One"
    elsif self == 2
      return "Two"
    elsif self == 3
      return "Three"
    elsif self == 4
      return "Four"
    elsif self == 5
      return "Five"
    elsif self == 6
      return "Six"
    elsif self == 7
      return "Seven"
    elsif self == 8
      return "Eight"
    elsif self == 9
      return "Nine"
    elsif self == 10
      return "Ten"
    end
  end
end

To Use it just put something like:
Code:
p = 10
p.to_word

:cheers:
 
yeah, you have to get it to check the number of digits before you convert, so that you can tell it how to convert it. Then you have to split the number into pieces before converting it. For example, 139,461 would be split like this: 1, 39, 4, 61. Then, you would convert it in the following format: 1= One + hundred, 39 = thirty-nine + thousand, 4 = four + hundred, 61 = sixty-one. (The thousand will vary depending on how many digits the number has before the decimal and which one you are looking at) You have to leave the and out instead of putting it beween the 4 and the 61, becasue in math, and represents a decimal point. (Like forty dollars and seventy-two cents) Then, you wouyld just put them back together, using the proper locations to insert something like a comma. If you did it right, it would turn out as one hundred thirty-nine thousand, four hundred sixty-one.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top