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

Add ability to change the behavior of our converter to number #8634

Closed
andrewtelnov opened this issue Jul 31, 2024 · 0 comments
Closed

Add ability to change the behavior of our converter to number #8634

andrewtelnov opened this issue Jul 31, 2024 · 0 comments
Assignees
Labels
enhancement user issue An issue or bug reported by users
Milestone

Comments

@andrewtelnov
Copy link
Member

andrewtelnov commented Jul 31, 2024

Add a callback function to override the default behavior:

//newValue could be NaN if it could not convert the value
parseNumber: (originalValue: any, newValue: number): number => newValue,

The following code should be write to convert the following strings to number: "123,0134,993". The default converter will return NaN for these strings:

import { settings, Helpers } from "survey-core";

settings.parseNumber = (originValue, numberValue) => {
    if(typeof originValue !== "string" || !originValue) return numberValue;
    if(originValue.indexOf(",") < 0) return numberValue;
    while(originValue.indexOf(",") > -1) {
      originValue = originValue.replace(",", "");
    }
    return Helpers.getNumber(originValue);
  };
@andrewtelnov andrewtelnov added enhancement user issue An issue or bug reported by users labels Jul 31, 2024
@andrewtelnov andrewtelnov self-assigned this Jul 31, 2024
andrewtelnov added a commit that referenced this issue Aug 2, 2024
…nverter

Add ability to change the behavior of our converter to number fix #8634
@OlgaLarina OlgaLarina added this to the v1.11.10 milestone Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement user issue An issue or bug reported by users
Projects
None yet
Development

No branches or pull requests

2 participants