I am trying to do something very similar to this c# docs example:
int value = 123;
Console.WriteLine(value.ToString(@"\#\#\# ##0 dollars and \0\0 cents \#\#\#"));
// Displays ### 123 dollars and 00 cents ###
Except I want it to actually work with decimals:
double value = 123.095;
Console.WriteLine(value.ToString(@"\#\#\# ##0 dollars and 0000 \#\#\#"));
// Should display ### 123 dollars and 0950 ###, but it doesn't (of course)
Tried:
Console.WriteLine(value.ToString(@"\#\#\# ##0. dollars and 0000 cents \#\#\#"));
But prints the decimal separator (of course), which I don’t want.
I know I could do something like this:
String.Format("{0:##0} {1:0000}", 123, 123);
But would very much like to avoid unless there is no other way
You can define your own special currency format, but… I’m not sure if I would do this. It kind of seems like an abuse of the NumberFormatInfo object:
EDIT: changed datatype of value from decimal to double
Output is “123 dollars and 0950 cents”
EDIT: it might make more sense to use CurrencyNegativePattern 15 instead of 8, so that negative values cause the entire string to be surrounded by parenthesis, which might be less confusing than just putting a negative sign in front of the dollars. For example, using CurrencyNegativePattern = 15 causes -123.095 to be output as “(123 dollars and 0950 cents)”