Why does using toString () in a float give different results in Firefox vs. Chrome vs. IE?

If you run this code in Firefox and Chrome, it will output another converted string.

(0.1234).toString(36) 

In Firefox, it will return the value "0.4fxcm49g2j8"

In Chrome or Node 4+ (probably the difference is V8), I get the value "0.4fxcm49g2j91m31w5nq6ldte29" .

In IE and Edge, this is "0.4fxcm49g2j91" (thanks @JaromandaX)

Does anyone know why? Just curious.

+5
source share
1 answer

It seems that Firefox cuts the line after max_chars (which is different for each view base), while Chrome does not.

I did not find any link in MDN, but if you check (for example) the same for radix = 35:

 Firefox: "0.4b5r4d4d4d4" Chrome: "0.4" 

You can check this in all browsers:

 for (var i = 11; i <=36; i++) { console.log(i, (0.1234).toString(i).length, (0.1234).toString(i)); } 

In chrome, the maximum length I got was 1101, and in firefox it was 19.

It looks like some kind of rounding when converting numbers between bases, however I'm not sure what / when / what round Firefox uses here.

+3
source

Source: https://habr.com/ru/post/1260557/


All Articles