Last active
August 22, 2017 05:13
-
-
Save vtno/af75d32db0487b72e64f2916ff8042df to your computer and use it in GitHub Desktop.
handle floating point annoying operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const preciseOperation = f => (a, b, decimalDigits) => { | |
decimalDigits = decimalDigits || 12 | |
+(f(a, b)).toFixed(decimalDigits) | |
} | |
const add = (a, b) => a + b | |
const minus = (a, b) => a - b | |
const multiply = (a, b) => a * b | |
const divide = (a, b) => a / b | |
export const preciseAdd = (a, b, decimalDigits) => preciseOperation(add)(a,b, decimalDigits) | |
export const preciseMinus = (a, b, decimalDigits) => preciseOperation(minus)(a,b, decimalDigits) | |
export const preciseMultiply = (a, b, decimalDigits) => preciseOperation(multiply)(a,b, decimalDigits) | |
export const preciseDivide = (a, b, decimalDigits) => preciseOperation(divide)(a,b, decimalDigits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment