#How does Medusa v2 avoid floating point rounding errors?

1 messages ยท Page 1 of 1 (latest)

golden brook
#

๐Ÿ‘† what the title says. Any ideas? Looking at the price_list entities makes it seem like it's not really being avoided?

export const AdminCreatePriceListPrice = z.object({
  currency_code: z.string(),
  amount: z.number(),
  variant_id: z.string(),
  min_quantity: z.number().nullish(),
  max_quantity: z.number().nullish(),
  rules: z.record(z.string(), z.string()).optional(),
})
karmic spruce
#

All the modules and workflows are using BigNumber to calculate things. You won't have any precision issue.
However this is not yet reflected on the API layer, the inputs, etc might not be 100% useful if you want to input large precision numbers.

#

For every numeric field on the DB, you have their correspondent raw column storing the full precision.

golden brook
#

So how should it be handled going forward? Two common ways: 1) enable string -> BigNumber serialisation in the API, 2) pass an explicit DTO in the API that has to be deserialised explicitly.

karmic spruce
#

When we get there, the numeric inputs will be similar to the type we have internally BigNumberInput, which can have many shapes.
But if you are working with the modules' services, this is already supported.
Did you have/find any issue or is it just a general question?