locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid serialization for floating numbers

abhishek6262 opened this issue · comments

There is a minor difference in the serialization done at the PHP and Javascript polyfill.

PHP will serialize 750.0 as d:750;
Whereas, Javascript implementation for the same will serialize it as i:750;

This happens due to the internal working of Javascript and PHP. But is there a way, we can handle this? We have a very specific use case of generating an md5 hashed key from the serialized value but due to this minor difference, the hashed value is completely different for both PHP and Javascript.

Hi @abhishek6262 thanks for reporting the issue. Unfortunately, this can't be solved. JavaScript has a single number type and the function just checks if it's a round number and serializes with i.