LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding off

Hello

 

Is there any block which can perform the operation given below ,

 

Input: 0.265 Output : 0.2

Input: 0.376  Output : 0.3

 

Basically the input has to be rounded off to just one decimal place.

 

Thanks

 

0 Kudos
Message 1 of 4
(2,745 Views)

You can create your own subVI.

multiply by 10, round to -infinity, divide by 10.

 

(Be aware that some of those fractional numbers (e.g. 0.1) don't have an exact representation in binary.)

Message 2 of 4
(2,722 Views)

Are you wanting to round, or are you wanting to truncate?

 

Rounding of 0.265 to one decimal place would give you 0.3. Likewise, rounding 0.376 would give you 0.4.

 

To truncate, I'd recommend converting your number to a string, searching the string for the decimal, taking the string subset to one character past the decimal, and converting back to a number.

 

Hope this helps.


0 Kudos
Message 3 of 4
(2,692 Views)

DanRen_IQA wrote:

To truncate, I'd recommend converting your number to a string, searching the string for the decimal, taking the string subset to one character past the decimal, and converting back to a number.


The Multiply, Round to -INF, Divide is a lot more efficient than converting data types.  I would not recommend the method of converting to strings and back.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(2,682 Views)