Having problem converting a string to an integer using sscanf

11 Ansichten (letzte 30 Tage)
hiaxis
hiaxis am 28 Jan. 2020
Kommentiert: Mohammad Sami am 29 Jan. 2020
Hi all, I'm having an issue converting a string to a number. See a copy of my problem below:
>> b = sscanf('123456789012345678', '%lu')
b =
4.2950e+009
Why is this happening? The same problem occurs all the way down to 10 digits. At 9, it returns the integer as expected. Your help is appreciated.
  7 Kommentare
Guillaume
Guillaume am 28 Jan. 2020
Yes, you could actually store the number if sscanf didn't convert to double. However since 123456789012345678 is greater than flintmax you'd be losing precision anyway (the number will get rounded down to 123456789012345680)
In any case, it does look like sscanf is limited to 32-bit numbers in your case.
Mohammad Sami
Mohammad Sami am 29 Jan. 2020
Can you try textscan ? Do you get the same issue with textscan ?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by