This widget could not be displayed.
This widget could not be displayed.

LabVIEW

This widget could not be displayed.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Round to Nearest Single precision Float

Solved!
Go to solution

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?

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 1 of 5
(1,447 Views)

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)

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Message 2 of 5
(1,444 Views)

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"

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 3 of 5
(1,418 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Message 4 of 5
(1,395 Views)

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.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Message 5 of 5
(1,353 Views)