{"version":3,"file":"decimal.cjs","names":[],"sources":["../../../src/common/data/decimal.ts"],"sourcesContent":["export type DecimalValue = number\nexport type DecimalInput = number | string | DecimalValue\n\n/** \n * The float returned is guaraneteed to have only the `decimalPlaces` length,\n * no rounding errors or float arithmetic artefacts. \n */\nexport function decimal(\n  value: DecimalInput,\n  decimalPlaces = 2,\n): DecimalValue {\n  return +(+value).toFixed(decimalPlaces)\n}\n\n/** `123` becomes `1.23` */\nexport function decimalFromCents(\n  value: DecimalInput,\n  decimalPlaces = 2,\n): DecimalValue {\n  return +(+value / 10 ** decimalPlaces).toFixed(decimalPlaces)\n}\n\n/** `1.23` becomes `123` */\nexport function decimalToCents(\n  value: DecimalInput,\n  decimalPlaces = 2,\n): number {\n  return Math.round(+value * 10 ** decimalPlaces)\n}\n\n/** `1.23` becomes `23` */\nexport function decimalCentsPart(\n  value: DecimalInput,\n  decimalPlaces = 2,\n): DecimalValue {\n  return 10 ** decimalPlaces * (decimal(value, decimalPlaces) % 1)\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,QACd,OACA,gBAAgB,GACF;AACd,QAAO,EAAE,CAAC,OAAO,QAAQ,cAAc;;;AAIzC,SAAgB,iBACd,OACA,gBAAgB,GACF;AACd,QAAO,EAAE,CAAC,QAAQ,MAAM,eAAe,QAAQ,cAAc;;;AAI/D,SAAgB,eACd,OACA,gBAAgB,GACR;AACR,QAAO,KAAK,MAAM,CAAC,QAAQ,MAAM,cAAc;;;AAIjD,SAAgB,iBACd,OACA,gBAAgB,GACF;AACd,QAAO,MAAM,iBAAiB,QAAQ,OAAO,cAAc,GAAG"}