question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to define a value within a response model that contains at least 2 decimal digits [QUESTION]

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
dmontagucommented, Feb 18, 2020

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).

2reactions
sm-Fifteencommented, Feb 17, 2020

I should probably mention that Pydantic has had max_digits and decimal_places restrictions for its condecimal 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 to NUMERIC(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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found