EnglishУкраїнськаmRussian
Login/New
Topic with no new replies

[BugWrong] Wrong conversion in function str2int


Author Message
Written on: 08. 05. 2017 [16:45]
wunker
Kamil Piecha
Topic creator
registered since: 28.09.2016
Posts: 8
Hello,

I have found a bug in str2int fuction. I had random problems with my code that converts some data stored in .txt file.
After research I found out that conversion of some numbers gives wrong results. For this moment I found:
-conversion of string "08" gives 0 as result.
-conversion of string "09" gives 0 as result.

Numbers written as string 0X from 0 to 7 after conversion gives expected result (number 0,1,2,3... etc).

As my test I was converting seconds from system time. Conversion performed by str2real gives good results.

Code below:
JAVASCRIPT
using Special.FLibSYS; 
 
	sSeconds = tmFStr(SYS.time(),"%S");
 
	messPut("SecondsString",1,sSeconds);
	messPut("SecondsInt",1,str2int(sSeconds));
	messPut("SecondsReal",1,str2real(sSeconds));




I was using lastest version (r2491).
Written on: 08. 05. 2017 [16:56]
roman
Roman Savochenko
Moderator
Contributor
Developer
registered since: 12.12.2007
Posts: 3750
"wunker" wrote:

I have found a bug in str2int fuction. I had random problems with my code that converts some data stored in .txt file.
After research I found out that conversion of some numbers gives wrong results. For this moment I found:
-conversion of string "08" gives 0 as result.
-conversion of string "09" gives 0 as result.

This is OK but for octal the value "08" and more is wrong!

"wunker" wrote:

messPut("SecondsInt",1,str2int(sSeconds));

If you mean that "sSeconds" is strongly decimal then use "base" of the function, like:
messPut("SecondsInt",1,str2int(sSeconds,10));

Then this isn't bug!

Learn, learn and learn better than work, work and work.
Written on: 08. 05. 2017 [17:02]
wunker
Kamil Piecha
Topic creator
registered since: 28.09.2016
Posts: 8
Indeed, this works. Thank You.



2460