you're going to need to split the number up by its "place"
I'm not sure what the bestest way to do this is but here's one solution: [code] public int[] GetPlaces(int value) { List result = new List(); // need to find the highest place int f = 1;
while (f <= value) f *= 10;
// then start getting each place starting with the highest order... while (f > 1) { f /= 10; result.Add(value/f); value = value%f; }
return result.ToArray(); } [/code]
So now you have an array of each "place" of the number
So if you pass 12345 into this function you will get an array {1, 2, 3, 4, 5} returned from this function.
Now your next step is to go through each of the places and build a string based on what number and place.
so...
int[] places = GetPlaces(12345);
if (places.Length == 1) { ... you only have to name what the number is... } else if (places.Length > 1) { ... you need to deal with "ten, eleven, twelve"... } if (places.Length > 2) { places[2] - " hundred and " } if (places.Length > 3) { places[3] - " thousand, " }
Comments
I'm not sure what the bestest way to do this is but here's one solution:
[code]
public int[] GetPlaces(int value)
{
List result = new List();
// need to find the highest place
int f = 1;
while (f <= value)
f *= 10;
// then start getting each place starting with the highest order...
while (f > 1)
{
f /= 10;
result.Add(value/f);
value = value%f;
}
return result.ToArray();
}
[/code]
So now you have an array of each "place" of the number
So if you pass 12345 into this function you will get an array {1, 2, 3, 4, 5} returned from this function.
Now your next step is to go through each of the places and build a string based on what number and place.
so...
int[] places = GetPlaces(12345);
if (places.Length == 1) { ... you only have to name what the number is... }
else if (places.Length > 1) { ... you need to deal with "ten, eleven, twelve"... }
if (places.Length > 2) { places[2] - " hundred and " }
if (places.Length > 3) { places[3] - " thousand, " }
and so on...