سؤال

"y851sq2vh4pf".to_i(36) #4504900070017571091

but

parseInt("y851sq2vh4pf",36) //4504900070017571300

How can I implement the Ruby to_i(36) function in Javascript? Why are the behaviors different?

هل كانت مفيدة؟

المحلول

Javascript doesn't have 64 bit integers, it only has double which loses accuracy for integers after 9007199254740992 (253)

Use a Big Number library like http://silentmatt.com/biginteger/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top