Reputation: 2440
How do I replace the decimal part of currency with 0's Here's my cuurency: 166.7 This is to be formatted as 000000016670
The length of this field is 12.
s.padright(12,0);
This is will the second part I believe.
The first part will involve replace the number after the decimal with 000..
Thanks
Upvotes: 0
Views: 123
Reputation: 6260
You can multiply by 100 then format the number.
var num = 166.7;
var numString = (num * 100).ToString("000000000000");
Multiplying by 100 turns 166.7 to 16670. Next you need to pad the left part of the number, which is what the ToString does. Each 0 represents a digit. It means, write the number that belongs to that digit, and if no number is present print 0.
Upvotes: 1