Typesafe floats ?

I'm trying to create a column called "weight". It needs to have values like "33.33" as floats. I'm using PostgreSQL - and I've created a column with the following settings; numeric('weight', { precision: 10, scale: 2 }) The thing is - when I try to insert a value like 33.33 it tells me that
number' is not assignable to type 'string'
number' is not assignable to type 'string'
If the numeric is a string - how can it be typesafe, as I can insert any string I want ? I mean PSQL will throw an error, but how can I make it typesafe ? Thank you guys
3 Replies
sevenwestonroads
sevenwestonroadsOP2y ago
At the moment - here's what I'm doing: weight: (100).toFixed(2)
Dan
Dan2y ago
use float/double precision
sevenwestonroads
sevenwestonroadsOP2y ago
float does not work in PSQL if I'm not mistaken. I've used this ->
weight: decimal('weight', { precision: 4, scale: 2 })
weight: decimal('weight', { precision: 4, scale: 2 })
But still got the string type
Want results from more Discord servers?
Add your server