I'm trying to define a JSON schema for a property
money: 12.12
My main concern is that a maximum of 2 decimal places should be allowed. My initial attempt at defining this field was
money: {
type: 'number',
minimum: 0,
multipleOf: 0.01
}
However, owing to floating point imprecision this fails. For example, using the tv4 validator, the number 147.41 passes validation, but 147.42 fails. Is there an alternative way to define a numeric type which will only allow a maximum of 2 decimal places?
It seems that the purpose of the "format" attribute is to implement these types of restrictions, but if I define the field like so:
money: {
type: 'number',
format: 'currency',
minimum: 0
}
Then how do I specify that fields with a 'currency' format should only allow up to 2 decimal places?