07-07-2023 01:59 AM
HI everyone i use labview 2019 I have a single precision float number which is "0.598" I need the number to be rounded to the value "0.600" or if it's "0.453" it becomes "0.500" or if it's "0.803" it becomes "0.800" and so on. Can someone help me?
Solved! Go to Solution.
07-07-2023 02:09 AM
One possibility. Multiply by 10, round to nearest integer, divide by 10.
(note that if you would display many more digits, they might not all be zero due to the limitations of floating point numbers and how they are represented in binary)
07-07-2023 02:41 AM
Perfect but is there a way to get even closer? like from "0.145" becomes "0.150" or "0.639" becomes "0.650" or "0.696" becomes "0.700"
07-07-2023 03:10 AM - edited 07-07-2023 03:26 AM
Hi a.,
@a.garciaperez wrote:
Perfect but is there a way to get even closer? like from "0.145" becomes "0.150" or "0.639" becomes "0.650" or "0.696" becomes "0.700"
So you want to round to multiples of 0.05? Multiply by 20…
Please define "getting closer" when it comes to simple math!
07-07-2023 04:33 AM
So basically you want to quantize the data to multiples of some fractional decimal value (that you never really define except with showing a very limited set of examples). As Gerd showed, the "multiply...round to nearest...divide" of course works with any step size.
As I already said, keep in mind that many of these simple decimal values (e.g. 0.1) don't have exact binary representation. Also be aware that LabVIEW uses bankers rounding, so if you want anything different for values that are exactly halfway, you need to work around that with a little bit more code.