Is it possible to define a value within a response model that contains at least 2 decimal digits [QUESTION]
See original GitHub issueDescription
Is it possible to define a value within a response model that contains at least 2 decimal digits.?
Additional context
The response model I am talking about looks like this:
class WindData(BaseModel):
speed: Union[List[float], List[None]] = Schema(
None,
title="Wind Speed [m/s]")
dir: Union[List[float], List[None]] = Schema(
None,
title="Wind Direction [°]")
gust: Union[List[float], List[None]] = Schema(
None,
title="Wind Speed [m/s]")
And the values should have maximal 2 decimal digits. I hope you can help me
Thanks a lot !
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Formatting a number with exactly two decimals in JavaScript
To format a number using fixed-point notation, you can simply use the toFixed method: (10.8).toFixed(2); // "10.80" var num = 2.4; alert(num.
Read more >Formulas—ArcGIS Survey123 | Documentation
A value of 0 may result in a blank answer. As with constraints, ensure that all decimal values between -1 and 1 in...
Read more >Unit 2 Section 2 : Decimals and Place Value
In this section we will look at the place values to the right of the decimal point. In the example questions, work out...
Read more >decimal — Decimal fixed point and floating point arithmetic ...
In decimal floating point, 0.1 + 0.1 + 0.1 - 0.3 is exactly equal to zero. ... Decimal numbers include special values such...
Read more >Place value with decimals (video) - Khan Academy
There is no limit to how far the decimal can go. 4 comments.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, there is also another challenge with decimal that pydantic json-encodes it to a float rather than a string (which can come with some float rounding issues if dumped and re-encoded).
I should probably mention that Pydantic has had
max_digits
anddecimal_places
restrictions for itscondecimal
type since very early versions (though those barely get a mention in the current documentation), which can be used together to have a constraint similar toNUMERIC(precision, scale)
in SQL. There’s no way to require a minimum or exact number of significant figures, though, at least not without a custom validator.