Numeric addition in ASP.net

Is there a way to format a numeric decimal number up to 12 digits?

I need to integrate the project with a payment gateway, and it says that

The amount must be filled with "0" on the left and not contain a decimal point. Example: 1 = 000000000100 or 1.5 = 000000000150

So far I have Convert.ToDecimal (amount) .ToString (). PadLeft (12, '0');

but it gives me 000000000015. I also tried .PadRight, but it does not give a result.

thanks

+4
source share
3 answers

Just multiply your number by 100.

Convert.ToDecimal(amount*100).ToString().PadLeft(12, '0')
+3
source

You can also try.

Convert.ToDecimal(amount).ToString("0000000000.00").Replace(".", "");
+1
source


- ( "D" ) (pads zeroes); - , .

int value; 

value = 12345;
Console.WriteLine(value.ToString("D"));
// Displays 12345
Console.WriteLine(value.ToString("D8"));
// Displays 00012345
+1

Source: https://habr.com/ru/post/1613933/


All Articles