Search code examples
stringdelphi-xe8int64

Delphi strToint64 initial with zero value


in Delphi XE8 I have to convert a '03213213210' string into an int64 a:=strToint64('03213213210');

I receive a = 3213213210; How can i receive? a = 03213213210;
Help me. Thank you.


Solution

  • An Int64 is a numeric value. It holds a number. Numbers have no concept of formatting, leading zeros, representation base etc. A number is just a number.

    Concepts such as binary, octal, decimal, hexadecimal have no impact on the value of the number, just its representation. Similarly, formatting requirements such as a set number of digits are not related to the value, but are a property of formatting of the value for display.

    In short, leading zeros are not a property of a number. Your Int64 variable contains the number. When you choose to display it, you may opt to enforce a set number of digits, for instance by padding with leading zeros to achieve that number. But that's not a property of the number, the Int64 variable. That's a property of how you choose to display it.

    So, if you really need to send the value as an Int64, then you have nothing more to do. If it needs to be displayed with 11 digits, with zero left padding, then that formatting is the responsibility of whoever displays it. On the other hand, it is possible that you should be holding the value as a string in order to preserve the formatting.

    I can't tell which of the two options above is what you need to do, but I can be quite sure that trying to store leading zeros in an Int64 is not the solution because that is not possible.