Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2025-01-18 16:44:09


> Actually, MySQL DECIMAL is fixed-point, not floating-point [1]. You
> can select the precision using DECIMAL(p, s), where p is the precision
> (between 1 and 65) and s is the scale (number of decimals). I'm
> assuming that, as long as p <= the precision for the corresponding
> Boost.Decimal type, things will work fine. For instance, decimal32
> would be interoperable with DECIMAL(7) and less precise, and so on.
>

> Is my assumption correct? Are there any caveats I should be aware of?
>

Using the example from the webpage DECIMAL(5,2) gives us the range -999.99 to 999.99, but decimal will store it as -9.9999e+02 to 9.9999e+02. As long as you limit yourself to chars_format::fixed on any potential output to the user you should be fine. One of the original users wanted to add bitcoin to their trading platform but the smallest divisible unit of a bitcoin, a satoshi = 1/100 million of a bitcoin, exceeded the precision of their in-house fixed point system so they switched to using decimal64.

Matt






Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk