Mafullah Backtrack Mafullah Backtrack - 6 months ago 11
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 :

000220
1
______ +
000221


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

Answer

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

Comments