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
Printable View
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? :ehh:Quote:
Originally Posted by Magiaus
write it yourself :) I don't think it exists
yeah, tell my boss. he wants the code but doesn't want me or my co workers writing it
hahaQuote:
Originally Posted by Magiaus
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:D
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.Quote:
Originally Posted by Magiaus
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.
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 = 0; i < mon.Length; i++)
{
for(int j = 0; j < mon[i].Length; j++)
{
switch(mon[i].Length)
{
case 1:
#region Ones
sCache = mon[i].Substring(j, 1);
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(j, 1);
iCache = int.Parse(sCache);
if(iCache > 0)
{
if(iCache == 1)
{
sCache = mon[i].Substring(j + 1, 1);
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(j, 1);
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(j, 1);
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(j, 1);
iCache = int.Parse(sCache);
if(iCache > 0)
{
if(iCache == 1)
{
sCache = mon[i].Substring(j + 1, 1);
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(j, 1);
iCache = int.Parse(sCache);
if(iCache > 0)
{
if(!skip)
{
if(mon[i].Substring(1, 1) != "0")
{
sb.Remove(sb.Length - 1, 1);
sb.Append("-");
}
sCache = ((Ones)iCache).ToString();
sb.Append(sCache);
}
}
skip = false;
sb.Append(" ");
break;
#endregion
}
#endregion
break;
}
#region Add Hundred..?
if(mon[i].Length == 3 && j == 0 && mon[i].Substring(j, 1) != "0")
{
sb.Append("Hundred");
sb.Append(" ");
}
#endregion
}
#region Add Power..?
if(i != (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
}
}
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
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...
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!!!"));
}