-
Notifications
You must be signed in to change notification settings - Fork 1
rounded_convert
Conversion functions rounded_convert
The rounded_convert function is similar to the convert function, except that the value is rounded to the nearest integer, instead of taking off the decimals.
In the following example, the 2.60[euro] in float32 representation is not exactly 2.60, as there is no exact binary floating point representation for this number. Instead, its binary representation is m*2^-e with m' and e` integer, which is more something like 2.599999..., and the amount in (non-rounded) cents is (after multiplying by 100) 259.9999..., which, when coverted to an integer representation with convert is rounded towards zero and becomes 259. When rounding to the nearest integer is more appropriate, use the rounded_convert function.
unit<float32> Euro := baseunit('euro', float32);
unit<uint16> Ct := uint16(0.01f * euro);
parameter<euro> euros := 2.60[euro];
parameter<Ct> centen := convert(euros, Ct);
parameter<Ct> centen_rounded := rounded_convert(euros, Ct);
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.