I am working with a decimal type in my application and have to submit that value as a string to a legacy web service which accepts values as strings. Its a payment value, so:
1000 => “100000” (1000 dollars and 00 cents)
131.11 => “13111”
I thought I’d multiply by 100 initially but ran into some cases that don’t work as expected.
EDIT:
OK I will clarify:
decimal val = 145.99m;
Console.WriteLine((val * 100).ToString());
results in:
14599.00
but I really need 14599 without the decimal points, since the value the other side is expecting is 145 dollars and 99 cents.
I was thinking there may be a different way rather than doing something like String.Replace(“.00”, string.Empty) or is this the only way?
If you want it to be 0 decimal places, you can do
myDecimal.ToString("0");.For example:
While if your decimal had more decimal places:
EDIT: If your decimal has extra decimal places, it performs an .5 away round. (in my experience, VS2008).