Skip to content

Parsing a number that uses comma as the decimal separator #3339

Answered by JacobWeisenburger
oehnstro asked this question in Q&A
Discussion options

You must be logged in to vote

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! 🙏
https://github.com/sponsors/JacobWeisenburger

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@oehnstro
Comment options

Answer selected by oehnstro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants