| 1352 | |
| 1353 | // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034 |
| 1354 | function floatSafeRemainder(val: number, step: number) { |
| 1355 | const valDecCount = (val.toString().split(".")[1] || "").length; |
| 1356 | const stepDecCount = (step.toString().split(".")[1] || "").length; |
| 1357 | const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount; |
| 1358 | const valInt = Number.parseInt(val.toFixed(decCount).replace(".", "")); |
| 1359 | const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", "")); |
| 1360 | return (valInt % stepInt) / 10 ** decCount; |
| 1361 | } |
| 1362 | |
| 1363 | export interface ZodNumberDef extends ZodTypeDef { |
| 1364 | checks: ZodNumberCheck[]; |