#Enforcing Numeric Format In Entity Column w/ TypeORM

1 messages · Page 1 of 1 (latest)

quiet bloom
#

My Coordinate Entity has three columns - x, y, & z - which will all contain a 5 digit number.

If the number is positive, it will be prefixed with a 1 to indicate positivity followed by the four digit coordinate (e.g. 19876).
If the number is negative, it will be prefixed with a 0 to indicate negativity followed by the four digit coordinate (e.g. 09876).

Is there a way to enforce that numeric pattern so I don't lose any prefixed 0s for coordinates that are either negative and / or less than 4 digits in length (e.g. 00987, 00087, 00007). I've looked at the TypeORM documentation (specifically, I've pored over the "Entity" section) to see if there were any tools I could use for this purpose but none were readily apparent. Any guidance you can offer would be much appreciated!

quiet bloom
#

So the "interim" solution for me on this one is to treat those fields as numbers for the time being that are "unformatted" and convert them to strings when I want them to be displayed in a formatted way. While it's not a complete match to my "vision" it's a good enough compromise that I can live with it.