Parsing a number that uses comma as the decimal separator #3339
-
Hi, I have a seemingly small task that I can't seem to get right. I need to parse the response from an external API. One field in the response is a string that contains a number that uses comma
The compiler then complains that:
What am I missing here? Any help or pointers in the right direction would be greatly appreciated 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Is this what you are looking for? const example = z.object( {
decimalNumber: z.string().transform( ( val ) => Number( `${ val }`.replace( ",", "." ) ) ).pipe( z.number() ),
} ) satisfies z.ZodSchema<{ decimalNumber: number }, z.ZodTypeDef, { decimalNumber: string }> If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
Is this what you are looking for?
If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger