sheetjs
sheetjs copied to clipboard
Fraction format gives incorrect results if there is text in the middle
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.
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.
Here is another couple strange cases, allowed by Excel (but not by the documentation):
? "a" / "b" 8
? "a" / "b" ?
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 '