Mafullah Backtrack Mafullah Backtrack - 2 years ago 69
SQL Question

Calculation without losing the digit number

I want to add between two of numbers from right. Number of one is "000220", the second is "1". After I was add of them, the result is "221".

How to add/increase that two both number without losing the zero or digit, like this :

______ +

I want to using for increment for sql from behind Code.

Answer Source

You could use string.PadLeft to add leading zeros after adding two integers.

    string one = "000220";
    string two = "1";

    (int.Parse(one) +int.Parse(two)).ToString().PadLeft(6,'0')

Working example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download