Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percent/Currency value types are incorrect #686

Closed
MartinDawson opened this issue Jun 5, 2021 · 14 comments
Closed

Percent/Currency value types are incorrect #686

MartinDawson opened this issue Jun 5, 2021 · 14 comments
Assignees
Labels
Bug Something isn't working

Comments

@MartinDawson
Copy link
Contributor

Actual:

1% & 1$ results in a valueType of NUMBER and a valueDetailedType of NUMBER_RAW.

Expected:

1% & 1$ should result in a valueType of NUMBER_PERCENT and NUMBER_CURRENCY.

Because the format is wrong if you then try and do getCellValue on it it will produce a NaN value. This means I cannot use getAllSheetsSerializedValues() and use that to build another sheet because it produces NaN results.

Steps to reproduce

Simple follow this steps here: https://handsontable.github.io/hyperformula/api/classes/hyperformula.html#getcellvaluedetailedtype

  • HyperFormula version: 0.6.0
  • Browser Name and version: Chrome latest
  • Operating System: Windows 10

Here's my testing showing the bad results:
image

@MartinDawson MartinDawson added the Bug Something isn't working label Jun 5, 2021
@izulin izulin self-assigned this Jun 5, 2021
@izulin
Copy link
Collaborator

izulin commented Jun 6, 2021

I am unable to reproduce this behaviour. Following code passes all tests for me:

    const engine = HyperFormula.buildFromArray([['1$', '1%']])
    const a1 = {sheet: 0, col: 0, row: 0}
    expect(engine.getCellValueType(a1)).toEqual('NUMBER')
    expect(engine.getCellValueDetailedType(a1)).toEqual('NUMBER_CURRENCY')
    expect(engine.getCellValueFormat(a1)).toEqual('$')
    expect(engine.getCellValue(a1)).toEqual(1)
    const b1 = {sheet: 0, col: 1, row: 0}
    expect(engine.getCellValueType(b1)).toEqual('NUMBER')
    expect(engine.getCellValueDetailedType(b1)).toEqual('NUMBER_PERCENT')
    expect(engine.getCellValueFormat(b1)).toEqual(undefined)
    expect(engine.getCellValue(b1)).toEqual(0.01)

@MartinDawson
Copy link
Contributor Author

@izulin thanks for replying/investigating so fast. That's strange, I'll look into it and see what's happening and get back here soon

@izulin
Copy link
Collaborator

izulin commented Jun 6, 2021

@MartinDawson two random things to check:

  • is the '$' and '%' sign actual dollar and percent (there might be some unicode weirdness of other characters looking similarly)

  • what are the engine options? you can get them with .getConfig() method

@MartinDawson
Copy link
Contributor Author

MartinDawson commented Jun 6, 2021 via email

@izulin
Copy link
Collaborator

izulin commented Jun 7, 2021

Trying to run the code from those unit tests might also help us debug it:

it('currency parsing', () => {

it('percentage parsing', () => {

@MartinDawson
Copy link
Contributor Author

MartinDawson commented Jun 7, 2021 via email

@MartinDawson
Copy link
Contributor Author

@izulin I tried running the unit tests and it worked fine for me on 14.x

However I tried in code sandbox and it doesn't work.

I think the issue is failing in js browser environments and working in nodejs.

See here please: https://codesandbox.io/s/quizzical-cache-6gbj8?file=/src/index.js

And observe the console.

@MartinDawson
Copy link
Contributor Author

Here's my config:


Config {accentSensitive: false, caseSensitive: false, caseFirst: "lower", ignorePunctuation: false, chooseAddressMappingPolicy: AlwaysDense…}
accentSensitive: false
caseSensitive: false
caseFirst: "lower"
ignorePunctuation: false
chooseAddressMappingPolicy: AlwaysDense
dateFormats: Array(2)
timeFormats: Array(2)
functionArgSeparator: ","
decimalSeparator: "."
language: "enGB"
licenseKey: ""
thousandSeparator: ""
localeLang: "en"
functionPlugins: Array(0)
gpujs: undefined
gpuMode: "gpu"
smartRounding: true
matrixDetection: true
matrixDetectionThreshold: 100
evaluateNullToZero: false
nullYear: 30
precisionRounding: 14
precisionEpsilon: 1e-13
useColumnIndex: false
useStats: false
binarySearchThreshold: 20
parseDateTime: ƒ defaultParseToDateTime() {}
stringifyDateTime: ƒ defaultStringifyDateTime() {}
stringifyDuration: ƒ defaultStringifyDuration() {}
translationPackage: TranslationPackage
errorMapping: Object
nullDate: Object
leapYear1900: false
undoLimit: 20
useRegularExpressions: false
useWildcards: true
matchWholeCell: true
maxRows: 40000
maxColumns: 18278
currencySymbol: Array(1)
<constructor>: "Config"

@izulin
Copy link
Collaborator

izulin commented Jun 9, 2021

The problem lies in the code relating to matrix detection, which is being phased out anyway.
Until new release comes, please do use matrixDetection: false option in the config. (e.g. HyperFormula.buildFromArray([["1%"]], { matrixDetection: false }))

In fact, this problem is not related to specific browser setting (which I am truly grateful for :) )
and can be replicated locally by running

const x = HyperFormula.buildFromArray([['1%']], {matrixDetection: true})
expect(x.getCellValue(adr('A1'))).toEqual(0.01)  // result is NaN

on e.g. 0.6.2 release

cc: @wojciechczerniak

@izulin
Copy link
Collaborator

izulin commented Jun 9, 2021

(or you can switch to develop branch if it is possible)

@MartinDawson
Copy link
Contributor Author

@izulin Turning off matrixDetection works so I'll do that for now.

Thank you

@izulin
Copy link
Collaborator

izulin commented Jun 9, 2021

Happy to help!

@izulin izulin closed this as completed Jun 9, 2021
@izulin
Copy link
Collaborator

izulin commented Jun 9, 2021

(This should be closed when we release new version.)

@izulin izulin reopened this Jun 9, 2021
@wojciechczerniak
Copy link
Contributor

Closing as done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants