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

Handle Precision in Decimal Numbers #126

Open
tobiasschweizer opened this issue Dec 12, 2019 · 2 comments
Open

Handle Precision in Decimal Numbers #126

tobiasschweizer opened this issue Dec 12, 2019 · 2 comments
Assignees
Labels
enhancement Improve existing code or new feature
Milestone

Comments

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Dec 12, 2019

Think about using a lib like https://www.npmjs.com/package/js-big-decimal to handle precision in decimal numbers so we do not loose information.

see #115 (comment)

remove https://github.com/dasch-swiss/knora-api-js-lib/blob/8eafba8796e536449253af1e12019bdde92bd1de/src/api/v2/resource/resources-endpoint.spec.ts#L243-L244

@tobiasschweizer tobiasschweizer self-assigned this Dec 12, 2019
@tobiasschweizer tobiasschweizer added the enhancement Improve existing code or new feature label Dec 12, 2019
@subotic subotic added this to the Backlog milestone Feb 7, 2020
@musicEnfanthen
Copy link

Had the same problem with JS in-built round method. Found this workaround (see link in the JSDOC) which could be helpful for your case, too?

    /**
     * Helper method: round.
     *
     * It rounds a given number to a given number of decimal places.
     * JS in-built round-method is sometimes not correct,
     * see: {@link http://www.jacklmoore.com/notes/rounding-in-javascript/}.
     *
     * @param {number} value The given input value to be rounded.
     * @param {number} decimals The given number of decimal places to round to.
     * @returns {number} The rounded number.
     */
    round(value: number, decimals: number): number {
        if (Number.isNaN(value)) {
            return;
        }
        return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
    } 

@tobiasschweizer
Copy link
Contributor Author

@musicEnfanthen I will look at that, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing code or new feature
Projects
None yet
Development

No branches or pull requests

3 participants