Xspreadsheet demo, number cell type detection improvments #2677

Closed
ThibautSF wants to merge 1 commits from patch-1 into master
ThibautSF commented 2022-05-10 13:30:00 +00:00 (Migrated from github.com)

Hi,

I just take notice that parseFloat() wasn't optimal due to incorrect guesses for strings beginning with numbers but containing other characters.

For examples :

//Integer+string
parseFloat('1x'); // => 1
Number('1x'); // => NaN
//Hexadecimal (parseFloat doesn't understand parse
parseFloat('0x10'); // => 0
Number('0x10'); // => 16

Note: This is a slight improvement but we might need further tests for some specific cases (described below) because I don't really know how it will react, but globally with Number() we get less data loss

  • empty/whitspace strings
parseFloat(''); // => NaN
Number(''); // => 0
parseFloat(' \r\n\t'); // => NaN
Number(' \r\n\t'); // => 0
  • some specific string like "Infinity"
parseFloat('Infinity'); // => NaN
Number('Infinity'); // => Infinity
  • booleans
parseFloat(false); // => NaN
Number(false); // => 0
Hi, I just take notice that `parseFloat()` wasn't optimal due to incorrect guesses for strings beginning with numbers but containing other characters. For examples : ```js //Integer+string parseFloat('1x'); // => 1 Number('1x'); // => NaN //Hexadecimal (parseFloat doesn't understand parse parseFloat('0x10'); // => 0 Number('0x10'); // => 16 ``` Note: This is a slight improvement but we might need further tests for some specific cases (described below) because I don't really know how it will react, but globally with `Number()` we get less data loss - empty/whitspace strings ```js parseFloat(''); // => NaN Number(''); // => 0 parseFloat(' \r\n\t'); // => NaN Number(' \r\n\t'); // => 0 ``` - some specific string like "Infinity" ```js parseFloat('Infinity'); // => NaN Number('Infinity'); // => Infinity ``` - booleans ```js parseFloat(false); // => NaN Number(false); // => 0 ```
SheetJSDev commented 2022-05-18 05:44:06 +00:00 (Migrated from github.com)
f1480ebd2ef13e5b357f17f027bea8f75196a186

Pull request closed

Sign in to join this conversation.
No description provided.