Fraction format gives incorrect results if there is text in the middle #2576

Open
opened 2020-09-27 21:37:15 +00:00 by snoopyjc · 3 comments
snoopyjc commented 2020-09-27 21:37:15 +00:00 (Migrated from github.com)

Another one from the valid.tsv suite: If a fraction format has text between the integer part and the fraction, then the result integer and denominator is wrong.

Example:

console.log(SSF.format('#"aabded"\\ ??/??', 12.3456789))

gives 10abded 00/81 instead of 12abded 28/81.

Another one from the valid.tsv suite: If a fraction format has text between the integer part and the fraction, then the result integer and denominator is wrong. Example: console.log(SSF.format('#"aabded"\\ ??/??', 12.3456789)) gives `10abded 00/81` instead of `12abded 28/81`.
snoopyjc commented 2020-09-27 21:56:40 +00:00 (Migrated from github.com)

In this case, this pattern is matching because fmt is set to #??/??:

if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) {

then frac is returning [0, 1000, 81] which is being split into 10 and 00.

In this case, this pattern is matching because fmt is set to `#??/??`: if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) { then `frac` is returning `[0, 1000, 81]` which is being split into `10` and `00`.
snoopyjc commented 2020-10-04 12:26:03 +00:00 (Migrated from github.com)

Here is another couple strange cases, allowed by Excel (but not by the documentation):

? "a" / "b" 8
? "a" / "b" ?
Here is another couple strange cases, allowed by Excel (but not by the documentation): ? "a" / "b" 8 ? "a" / "b" ?
snoopyjc commented 2020-10-04 12:36:06 +00:00 (Migrated from github.com)

And just when you thought it can't get any stranger, Excel also suppresses anything after the integer part if the fraction is not needed:

format('# "h" ? "a" / "b" ?', 1.2) -> '1 h 1 a / b 5'
format('# "h" ? "a" / "b" ?', 1)   -> '1            '
And just when you thought it can't get any stranger, Excel also suppresses anything after the integer part if the fraction is not needed: format('# "h" ? "a" / "b" ?', 1.2) -> '1 h 1 a / b 5' format('# "h" ? "a" / "b" ?', 1) -> '1 '
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2576
No description provided.