Store percentage value as integer

Hi,

I realised once again how awesome Drizzle is! I want to store percentage value as integer. I ended up with this:
export const percentage = customType<{ data: number, driverData: number }>({
  dataType() {
    return 'integer'
  },
  toDriver(value: number) {
    return Math.round(value * 100)
  },
  fromDriver(value: number) {
    return value / 100
  }
})

For my use case, it is correct as I don't want to store more than 2 decimals. Using the type decimal is inconvenient as it is stored as string with the Postgres driver. Hence this choice.

But my question is about the caveats of this technique. Does the in & out conversion affect the performance in a noticeable way?
Was this page helpful?