parseInt() value help
-
Hey guys,
I'm using parsInt() to convert text from a label into an integer. Seems to work properly EXCEPT when I add a 0 in front of 8 or 9.01 = 1
05 = 5
08 = 0
09 = 0
90 = 90
33333 = 33333
Here's a simplified example:HiseSnippet 947.3ocsV0raaiCDlxwLn1sdQKPuWgbot.oFxo+s.EEqarcJL1FGg3jhdqkVh1lanHEnn5Vih9hzS6ix9xr222ftCEksjaTBZLvpSdl4al4aFNbn8Ux.ZRhTgbZb1xXJx4N3IKE5E8WPXBznAFEwDUB0USSznCWFSRRngHGmcdiAgSi5nru+82NjvIh.ZgJD5cRV.8srHltPqeuemw4GQBomwhJg9o8FEHE8kbYJvlcvdnXRvEj4zwDCrZXjytCCYZoZhl.jAvbnLb4jEx+TXw+NVBaJmZD5hl.AxpF0eAiG5upRSPHm59E08N15993iYgr05Kp+6lYvsvix8.mZaRo5aPotWEkNRxCMA3JnmSI5U2Ru6gmDnXw5BKFtca7HglplQf1dYZYwhp8fZ39R.gP2IhbA8HEHr1i1O2yae2m448nW1pYqlPyOQ69IhxkSlR4Z3vQ49J2gh4LAsSfhBUn4DScxz+fFnaa7p.YmDMQoyr2thP9VCvtP3VQm4TceYTrT.Bs2yZdOiW+fOGb89bvd1LUlHTKM5S37ovDT6Yoh.MSJZ+nVM+hArK7YR.SDmpg3aytI7s2SS+rNKlFPPhSjbZmXECxXF7UlrY2jrbe12M6Zxn0.MH+pkcqXfqTLVpom.To4WZ1n4Wa59illMqRalVfRx4P2sJy19903XaQZzTpZent4oz0.gwqMmeu8O27af8DoDPoXjfoOIllKWLgarYq5UV8PqK1xpJpwxZsibWFVgpKeABkOw.+57QCHZh4NUtN.WLUoYlp0Y.8SvBJ6MrF3AzjKzxXnordLC4f0YVake+K6bGwfJ6WviF6e9YtiO+3CGdJ5yEaxF2a4Zgd98nPGlj0Dc1AUJx6dUQ9VX6DY4X5WJl+866YF4.dh85hlNe0NyF6he32+VFjaPZNnTZ9KUUoowtN46yKmq+Ae4bckMq6h8e8oSFNvcz3yF9lMZWeTcMsqKuHDVGKCS4D8l6nMOFka.F72XYnYgmHgoWV9wpavhauJWb2sp4teR5dOrOSGrnZ9VqB9Byu+ey27mAagGNaFrdufr0wG89s8Mua.UNUlpYh4GSzJFLbfGmFMAlzBn.SDBJGRD1olYbyJ6YjMclITQXlv2gubicMxN4F6txHJhDnjeHvt.w7P6sxz.bRj8eLZfO1H61EkslD7C60wCEAu++gf.Sq3w.2q1mC1BedxV3yS2Bed1V3yy2BedwV3yuds9X9qWuNUKirWS.E9CyVn63LTX1RjMQh9O.ZJgeN
-
parseInt
sometimes does weird things. UseMath.round()
instead. -
-
@Christoph-Hart thanks for this! Math.round gets the job done, so I'm happy :)
-
Welp, it's August, so "08" by JUCE time, and this just broke all of my licensing systems lol. Time for an update to
Math.round()
-
Wow that sounds super annoying.
If you want to globally deactivate octal number parsing, just make that function return always
false
: -
@Christoph-Hart Thanks Christoph
Is This Helps To Fix The Frontendmacros Aswell?
Values Looks Strange There Too -
Update:
Return False is NOT The Answer :/
And Console, Shows This Error, Even In A Project WIth Nothing Than GUI SizeLine 1, column 28: Syntax error in numeric constant {SW50ZXJmYWNlfHwyN3wxfDI4}
-
@Christoph-Hart It's all good. It was a 5 minute fix, but a several hour debug haha. Fortunately, I don't think it broke the compiled plugin.
-
confused
I just used this function to parse date and time. It's OK when using javascript in browser.
for(var i = 0; i < 10; i++) console.log(parseInt("0" + i)); // 0 1 2 3 4 5 6 7 8 9
but weird in HISE:
for(i = 0; i < 10; i++) Console.print(parseInt("0" + i)); // 0 1 2 3 4 5 6 7 0 0
finally, I do a trick:
for(i = 0; i < 10; i++) Console.print(parseInt("+0" + i)); // 0 1 2 3 4 5 6 7 8 9
-
@civet HISEScript != javascript
-
@Lindon Yes, I know. I have read the docs carefully.
but
parseInt()
is very commonly used in scripts. and it's likelyparseInt()
in HISE does not support the second parameter.parseInt("010", 10); // always return 8 in HISE