LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

decimal value format to whole value

Solved!
Go to solution

I have a VI that when run, can return one of the various answers with a decimal format displayed below:

 

1.3661

13.661

136.61

1366.1

 

For any of these return values, I would like to format the value to return 4 digits as a whole number like this:

 

1336

 

 

 

 

0 Kudos
Message 1 of 11
(2,255 Views)
Solution
Accepted by topic author robertgalusha

Hi Robert,

 


@robertgalusha wrote:

1.3661

13.661

136.61

1366.1

For any of these return values, I would like to format the value to return 4 digits as a whole number like this:

1336


What is the question?

What have you tried? Where are you stuck?

Are there other things to consider? (Like negative numbers with leading minus char!?)

What is the expected input range of those numeric values?

 

Ideas:

  • Convert the number to string, replace the point by an empty char, keep the first 4 chars, (convert back to integer if needed)…
  • Use some math to scale the numeric value to the range [1000, 9999], then round to next integer…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,229 Views)

Are you trying to return the four significant digits?  Is this some kind of homework exercise?  (Note: if it is, it doesn't disqualify you from receiving a solution, but it may determine how we help you arrive at one.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 11
(2,207 Views)

@robertgalusha wrote:

I have a VI that when run, can return one of the various answers with a decimal format displayed below:

 

1.3661

13.661

136.61

1366.1

 

For any of these return values, I would like to format the value to return 4 digits as a whole number like this:

 

1336

 

 

 

 


Just trying to figure out the pattern here, all of your numbers have 13661 with the decimal place moving around, but you want to return 1336. Is that right, or do you really want 1366?

 

Kind of brute force, but I would convert to fractional string, search and replace "." with "" (empty string), and get string subset of length 4.

0 Kudos
Message 4 of 11
(2,191 Views)

Maybe something like that?

 

altenbach_0-1621469420220.png

 

 

0 Kudos
Message 5 of 11
(2,161 Views)

I would like to format the value to return 4 digits as a whole number like this:

1336

 


I should wait for the "is this homework?" reply, but since Altenbach already posted a solution, I couldn't resist:

thols_1-1621512695330.png

 

Are you sure it's not 1337 you want to return? In that case you can do like this:

thols_0-1621512576886.png

 

Certified LabVIEW Architect
0 Kudos
Message 6 of 11
(2,121 Views)

 

Ideas:

  • Convert the number to string, replace the point by an empty char, keep the first 4 chars, (convert back to integer if needed)…
  • Use some math to scale the numeric value to the range [1000, 9999], then round to next integer…
Best regards,
GerdW
 
 
GerdW.....This worked & did what was needed.
 
Thanks
0 Kudos
Message 7 of 11
(2,111 Views)

Hi Robert,

 

I would prefer the "math" way as suggested and as shown by Christian…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(2,106 Views)

@robertgalusha wrote:

 

Ideas:

  • Convert the number to string, replace the point by an empty char, keep the first 4 chars, (convert back to integer if needed)…
  • Use some math to scale the numeric value to the range [1000, 9999], then round to next integer…
 
GerdW.....This worked & did what was needed.
 

You did not say what "this" is that worked (there are two suggestions!), but if you implemented the first option, it will fail if the input number is less than 1. You would also need to deal with leading zeroes, etc.

0 Kudos
Message 9 of 11
(2,087 Views)

@thols wrote:

I would like to format the value to return 4 digits as a whole number like this:

1336

 


I should wait for the "is this homework?" reply, but since Altenbach already posted a solution, I couldn't resist:

thols_1-1621512695330.png

 

Are you sure it's not 1337 you want to return? In that case you can do like this:

thols_0-1621512576886.png

 


I already furnished this response a few posts back.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 11
(2,070 Views)