Results 1 to 10 of 10

Thread: ToString(OnMoney) [Resolved]

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Resolved ToString(OnMoney) [Resolved]

    I need a way to convert $100,000 to One Hundred Thousand Dollars....

    I need to not have to write the method.....

    I need help....

    HELP
    Last edited by Magiaus; Mar 27th, 2005 at 05:56 PM.
    Magiaus

    If I helped give me some points.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: ToString(OnMoney)

    Quote Originally Posted by Magiaus
    I need a way to convert $100,000 to One Hundred Thousand Dollars....

    I need to not have to write the method.....

    I need help....

    HELP
    uuh huh?
    write it yourself I don't think it exists
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: ToString(OnMoney)

    yeah, tell my boss. he wants the code but doesn't want me or my co workers writing it
    Magiaus

    If I helped give me some points.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: ToString(OnMoney)

    Quote Originally Posted by Magiaus
    yeah, tell my boss. he wants the code but doesn't want me or my co workers writing it
    haha
    he wants someone here to write the function for you guys? or you mean he wants to find a way to do it with .NET without writing any code? cuz I dont think .NET has somethign for that

    p.s. one more post and you'd have 1111 posts
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ToString(OnMoney)

    Quote Originally Posted by Magiaus
    yeah, tell my boss. he wants the code but doesn't want me or my co workers writing it
    Not possible. Either that or look for an existing snippet of code or class library that'll do that for you. Either way, code has to be written.

  6. #6

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: ToString(OnMoney)

    nah, he doesn't want someone here to write it. I was hoping maybe someone had a snipet of something like that. It's for printing checks I think. Number in the DB, pull the number run it through the method, and draw it.
    Magiaus

    If I helped give me some points.

  7. #7

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Cool just remember i !didn't write this.....

    PHP Code:
    using System;
    using System.Collections;
    using System.Text;

    namespace 
    MoneyString
    {
        
    /// <summary>Dummy Class to hold method</summary>
        
    public class Money 
        
    {
            
    #region Enumerations
            
    enum MoneyPower
            
    {
                
    Hundred        1,
                
    Thousand    2,
                
    Million        3,
                
    Billion        4,
                
    Trillion    5
            
    }
            
    enum Ones
            
    {
                
    One        1,
                
    Two        2,
                
    Three    3,
                
    Four    4,
                
    Five    5,
                
    Six        6,
                
    Seven    7,
                
    Eight    8,
                
    Nine    9
            
    }
            
    enum Tens
            
    {
                
    Ten        1,
                
    Twenty    2,
                
    Thirty    3,
                
    Forty    4,
                
    Fifty    5,
                
    Sixty    6,
                
    Seventy    7,
                
    Eighty    8,
                
    Ninenty    9
            
    }
            
    enum TensSpecial
            
    {
                
    Eleven        1,
                
    Twelve        2,
                
    Thirteen    3,
                
    Fourteen    4,
                
    Fithteen    5,
                
    Sixteen        6,
                
    Seventeen    7,
                
    Eightteen    8,
                
    Nineteen    9
            
    }
            
    #endregion
            #region Methods
            /// <summary>
            /// Transforms a number into an English(Word) Readable Money Value.
            /// </summary>
            /// <param name="money">A number.</param>
            /// <returns>English Word Money String.</returns>
            
    public static string ToString(int money)
            {
                
    #region var
                
    StringBuilder sb = new StringBuilder();
                
    string[] mon money.ToString("C").Split(',');
                
    string ret "";
                
    string sCache "";
                
    int iCache 0;
                
    bool skip false;
                
    #endregion
                #region Return if Number is to Large
                
    if(mon.Length 5) return ret//more than 5 is alot of money
                #endregion
                #region clean string
                
    mon[0] = mon[0].Replace("$",""); //remove dollar sign
                
    mon[mon.Length 1] = mon[mon.Length 1].Split('.')[0]; //trim of the decimal places
                #endregion
                #region Loopy Money Switch
                
    for(int i 0mon.Lengthi++)
                {
                    for(
    int j 0mon[i].Lengthj++)
                    {
                        switch(
    mon[i].Length)
                        {
                            case 
    1:
                                
    #region Ones
                                
    sCache mon[i].Substring(j1);
                                
    iCache int.Parse(sCache);
                                if(
    iCache 0)
                                {
                                    
    sCache = ((Ones)iCache).ToString();
                                    
    sb.Append(sCache);
                                }
                                
    sb.Append(" ");
                                break;
                                
    #endregion
                            
    case 2:
                                
    #region Place Switch
                                
    switch(j)
                                {
                                    case 
    0:
                                        
    #region Tens
                                        
    sCache mon[i].Substring(j1);
                                        
    iCache int.Parse(sCache);
                                        if(
    iCache 0)
                                        {
                                            if(
    iCache == 1)
                                            {
                                                
    sCache mon[i].Substring(11);
                                                
    iCache int.Parse(sCache);
                                                
    sCache = ((TensSpecial)iCache).ToString();
                                                
    sb.Append(sCache);
                                                
    skip true;
                                            }
                                            else
                                            {
                                                
    sCache = ((Tens)iCache).ToString();
                                                
    sb.Append(sCache);
                                            }
                                        }
                                        
    sb.Append(" ");
                                        break;
                                        
    #endregion
                                    
    case 1:
                                        
    #region Ones
                                        
    if(!skip)
                                        {
                                            
    sCache mon[i].Substring(j1);
                                            
    iCache int.Parse(sCache);
                                            if(
    iCache 0)
                                            {
                                                
    sCache = ((Ones)iCache).ToString();
                                                
    sb.Append(sCache);
                                            }
                                            
    sb.Append(" ");
                                        }
                                        
    skip false;
                                        break;
                                        
    #endregion
                                
    }
                                
    #endregion
                                
    break;
                            case 
    3:
                                
    #region Place Swich
                                
    switch(j)
                                {
                                    case 
    0:
                                        
    #region Hundreds
                                        
    sCache mon[i].Substring(j1);
                                        
    iCache int.Parse(sCache);
                                        if(
    iCache 0)
                                        {
                                            
    sCache = ((Ones)iCache).ToString();
                                            
    sb.Append(sCache);
                                            
    sb.Append(" ");
                                        }
                                        
    sb.Append(" ");
                                        break;
                                        
    #endregion
                                    
    case 1:
                                        
    #region Tens
                                        
    sCache mon[i].Substring(j1);
                                        
    iCache int.Parse(sCache);
                                        if(
    iCache 0)
                                        {
                                            if(
    iCache == 1)
                                            {
                                                
    sCache mon[i].Substring(11);
                                                
    iCache int.Parse(sCache);
                                                
    sCache = ((TensSpecial)iCache).ToString();
                                                
    sb.Append(sCache);
                                                
    skip true;
                                            }
                                            else
                                            {
                                                
    sCache = ((Tens)iCache).ToString();
                                                
    sb.Append(sCache);
                                                
    skip false;
                                            }
                                        }
                                        
    sb.Append(" ");
                                        break;
                                        
    #endregion
                                    
    case 2:
                                        
    #region Ones
                                        
    sCache mon[i].Substring(j1);
                                        
    iCache int.Parse(sCache);
                                        if(
    iCache 0)
                                        {
                                            if(!
    skip)
                                            {
                                                if(
    mon[i].Substring(11) != "0"
                                                {
                                                    
    sb.Remove(sb.Length 11);
                                                    
    sb.Append("-");
                                                }
                                                
    sCache = ((Ones)iCache).ToString();
                                                
    sb.Append(sCache);
                                            }
                                        }
                                        
    skip false;
                                        
    sb.Append(" ");
                                        break;
                                        
    #endregion
                                
    }
                                
    #endregion
                                
    break;
                        }
                        
    #region Add Hundred..?
                        
    if(mon[i].Length == && == && mon[i].Substring(j1) != "0")
                        {
                            
    sb.Append("Hundred");
                            
    sb.Append(" ");
                        }
                        
    #endregion
                    
    }
                    
    #region Add Power..?
                    
    if(!= (mon.Length 1))
                    {
                        
    sCache = ((MoneyPower)mon.Length i).ToString();
                        
    sb.Append(sCache);
                        
    sb.Append(" ");
                    }
                    
    #endregion
                
    }
                
    #endregion
                #region Get, Append Dollars, and Return English Money String
                
    ret sb.ToString();
                
    ret += "Dollars";
                return 
    ret;
                
    #endregion
            
    }
            
    #endregion
        
    }

    Magiaus

    If I helped give me some points.

  8. #8

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    anybody with a sec please look for errors

    Test #1
    Numeric Value: $389,621,788.00
    English Value: Three Hundred Eighty-Nine Million Six Hundred Twenty-One Thousand Seven Hundred Eighty-Eight Dollars

    Test #2
    Numeric Value: $1,865,080,772.00
    English Value: One Billion Eight Hundred Sixty-Five Million Eighty Thousand Seven Hundred Seventy-Two Dollars

    Test #3
    Numeric Value: $345,351,826.00
    English Value: Three Hundred Forty-Five Million Three Hundred Fifty-One Thousand Eight Hundred Twenty-Six Dollars

    Test #4
    Numeric Value: $1,339,857,015.00
    English Value: One Billion Three Hundred Thirty-Nine Million Eight Hundred Fifty-Seven Thousand Fithteen Dollars

    Test #5
    Numeric Value: $209,330,292.00
    English Value: Two Hundred Nine Million Three Hundred Thirty Thousand Two Hundred Ninenty-Two Dollars

    Test #6
    Numeric Value: $1,927,514,329.00
    English Value: One Billion Nine Hundred Twenty-Seven Million Five Hundred Fourteen Thousand Three Hundred Twenty-Nine Dollars

    Test #7
    Numeric Value: $1,589,235,865.00
    English Value: One Billion Five Hundred Eighty-Nine Million Two Hundred Thirty-Five Thousand Eight Hundred Sixty-Five Dollars

    Test #8
    Numeric Value: $972,422,605.00
    English Value: Nine Hundred Seventy-Two Million Four Hundred Twenty-Two Thousand Six Hundred Five Dollars

    Test #9
    Numeric Value: $445,753,184.00
    English Value: Four Hundred Forty-Five Million Seven Hundred Fifty-Three Thousand One Hundred Eighty-Four Dollars

    Test #10
    Numeric Value: $1,126,061,060.00
    English Value: One Billion One Hundred Twenty-Six Million Sixty-One Thousand Sixty Dollars

    Test #11
    Numeric Value: $709,148,599.00
    English Value: Seven Hundred Nine Million One Hundred Forty-Eight Thousand Five Hundred Ninenty-Nine Dollars

    Test #12
    Numeric Value: $1,924,106,281.00
    English Value: One Billion Nine Hundred Twenty-Four Million One Hundred Six Thousand Two Hundred Eighty-One Dollars

    Test #13
    Numeric Value: $221,823,002.00
    English Value: Two Hundred Twenty-One Million Eight Hundred Twenty-Three Thousand Two Dollars

    Test #14
    Numeric Value: $1,337,181,017.00
    English Value: One Billion Three Hundred Thirty-Seven Million One Hundred Eighty-One Thousand Seventeen Dollars

    Test #15
    Numeric Value: $2,072,903,015.00
    English Value: Two Billion Seventy-Two Million Nine Hundred Three Thousand Fithteen Dollars

    Test #16
    Numeric Value: $1,595,375,838.00
    English Value: One Billion Five Hundred Ninenty-Five Million Three Hundred Seventy-Five Thousand Eight Hundred Thirty-Eight Dollars

    Test #17
    Numeric Value: $167,100,512.00
    English Value: One Hundred Sixty-Seven Million One Hundred Thousand Five Hundred Twelve Dollars

    Test #18
    Numeric Value: $2,136,624,496.00
    English Value: Two Billion One Hundred Thirty-Six Million Six Hundred Twenty-Four Thousand Four Hundred Ninenty-Six Dollars

    Test #19
    Numeric Value: $1,974,424,292.00
    English Value: One Billion Nine Hundred Seventy-Four Million Four Hundred Twenty-Four Thousand Two Hundred Ninenty-Two Dollars

    Test #20
    Numeric Value: $1,369,066,427.00
    English Value: One Billion Three Hundred Sixty-Nine Million Sixty-Six Thousand Four Hundred Twenty-Seven Dollars

    Test #21
    Numeric Value: $1,157,989,415.00
    English Value: One Billion One Hundred Fifty-Seven Million Nine Hundred Eighty-Nine Thousand Four Hundred Fithteen Dollars

    Test #22
    Numeric Value: $107,525,180.00
    English Value: One Hundred Seven Million Five Hundred Twenty-Five Thousand One Hundred Eighty Dollars

    Test #23
    Numeric Value: $848,059,307.00
    English Value: Eight Hundred Forty-Eight Million Fifty-Nine Thousand Three Hundred Seven Dollars

    Test #24
    Numeric Value: $1,374,717,657.00
    English Value: One Billion Three Hundred Seventy-Four Million Seven Hundred Seventeen Thousand Six Hundred Fifty-Seven Dollars

    Test #25
    Numeric Value: $1,080,978,991.00
    English Value: One Billion Eighty Million Nine Hundred Seventy-Eight Thousand Nine Hundred Ninenty-One Dollars

    Test #26
    Numeric Value: $936,497,048.00
    English Value: Nine Hundred Thirty-Six Million Four Hundred Ninenty-Seven Thousand Forty-Eight Dollars

    Test #27
    Numeric Value: $1,702,947,944.00
    English Value: One Billion Seven Hundred Two Million Nine Hundred Forty-Seven Thousand Nine Hundred Forty-Four Dollars

    Test #28
    Numeric Value: $971,513,228.00
    English Value: Nine Hundred Seventy-One Million Five Hundred Thirteen Thousand Two Hundred Twenty-Eight Dollars

    Test #29
    Numeric Value: $589,727,001.00
    English Value: Five Hundred Eighty-Nine Million Seven Hundred Twenty-Seven Thousand One Dollars

    Test #30
    Numeric Value: $637,511,390.00
    English Value: Six Hundred Thirty-Seven Million Five Hundred Eleven Thousand Three Hundred Ninenty Dollars

    Test #31
    Numeric Value: $1,489,858,776.00
    English Value: One Billion Four Hundred Eighty-Nine Million Eight Hundred Fifty-Eight Thousand Seven Hundred Seventy-Six Dollars

    Test #32
    Numeric Value: $1,068,202,291.00
    English Value: One Billion Sixty-Eight Million Two Hundred Two Thousand Two Hundred Ninenty-One Dollars

    Test #33
    Numeric Value: $1,227,397,995.00
    English Value: One Billion Two Hundred Twenty-Seven Million Three Hundred Ninenty-Seven Thousand Nine Hundred Ninenty-Five Dollars

    Test #34
    Numeric Value: $66,395,648.00
    English Value: Sixty Six Million Three Hundred Ninenty-Five Thousand Six Hundred Forty-Eight Dollars

    Test #35
    Numeric Value: $321,846,843.00
    English Value: Three Hundred Twenty-One Million Eight Hundred Forty-Six Thousand Eight Hundred Forty-Three Dollars

    Test #36
    Numeric Value: $1,644,486,207.00
    English Value: One Billion Six Hundred Forty-Four Million Four Hundred Eighty-Six Thousand Two Hundred Seven Dollars

    Test #37
    Numeric Value: $85,852,088.00
    English Value: Eighty Five Million Eight Hundred Fifty-Two Thousand Eighty-Eight Dollars

    Test #38
    Numeric Value: $601,929,525.00
    English Value: Six Hundred One Million Nine Hundred Twenty-Nine Thousand Five Hundred Twenty-Five Dollars

    Test #39
    Numeric Value: $202,480,259.00
    English Value: Two Hundred Two Million Four Hundred Eighty Thousand Two Hundred Fifty-Nine Dollars

    Test #40
    Numeric Value: $1,372,891,284.00
    English Value: One Billion Three Hundred Seventy-Two Million Eight Hundred Ninenty-One Thousand Two Hundred Eighty-Four Dollars

    Test #41
    Numeric Value: $263,488,857.00
    English Value: Two Hundred Sixty-Three Million Four Hundred Eighty-Eight Thousand Eight Hundred Fifty-Seven Dollars

    Test #42
    Numeric Value: $881,059,013.00
    English Value: Eight Hundred Eighty-One Million Fifty-Nine Thousand Thirteen Dollars

    Test #43
    Numeric Value: $873,976,257.00
    English Value: Eight Hundred Seventy-Three Million Nine Hundred Seventy-Six Thousand Two Hundred Fifty-Seven Dollars

    Test #44
    Numeric Value: $369,049,193.00
    English Value: Three Hundred Sixty-Nine Million Forty-Nine Thousand One Hundred Ninenty-Three Dollars

    Test #45
    Numeric Value: $534,045,915.00
    English Value: Five Hundred Thirty-Four Million Forty-Five Thousand Nine Hundred Fithteen Dollars

    Test #46
    Numeric Value: $383,814,053.00
    English Value: Three Hundred Eighty-Three Million Eight Hundred Fourteen Thousand Fifty-Three Dollars

    Test #47
    Numeric Value: $1,009,233,527.00
    English Value: One Billion Nine Million Two Hundred Thirty-Three Thousand Five Hundred Twenty-Seven Dollars

    Test #48
    Numeric Value: $1,839,847,372.00
    English Value: One Billion Eight Hundred Thirty-Nine Million Eight Hundred Forty-Seven Thousand Three Hundred Seventy-Two Dollars

    Test #49
    Numeric Value: $1,638,638,647.00
    English Value: One Billion Six Hundred Thirty-Eight Million Six Hundred Thirty-Eight Thousand Six Hundred Forty-Seven Dollars

    Test #50
    Numeric Value: $1,122,999,471.00
    English Value: One Billion One Hundred Twenty-Two Million Nine Hundred Ninenty-Nine Thousand Four Hundred Seventy-One Dollars
    Attached Files Attached Files
    Magiaus

    If I helped give me some points.

  9. #9
    Lively Member MedevH's Avatar
    Join Date
    Aug 2001
    Location
    Where I walk, I walk alone. Where I code, I code alone.
    Posts
    91

    Re: ToString(OnMoney)

    Hey Magiaus,
    That is some seriously jacked-up code man...
    Where you steal that from a Dreamweaver behaviour? LOL!

    everything looks good I didn't catch any errors ok I'm not gonna lie I didn't go through them all, just up to about the first 30 or so but hell no errors in 30 thats pretty tops hos... *tips hat*

    Just remember I didn't write this either...
    There is no good or evil only CODE! ~MedevH~

  10. #10

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: ToString(OnMoney)

    Dude, it was harder than it should have been to !(!write) that code. !(!My) head was going in these weird nested loops where I had to proc a certian thing but it was going backwards...... and then !(!I) had to use a number to to figure out what number !(!I) was on.

    Then !(!I) was like hey if !(!I) make an enum I can use a number to get a word hmmm..... !(!I) says.... hmmm.... and it all became clear.
    Code:
    if(!(!Magiaus) == !(!true))
    {
        throw new Exception("W-T-F!!!", new Exception("No Really, W-T-F!!!"));
    }
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width