Jump to content

Numeric display decimal places


Recommended Posts

Hi,

I'm reading a floating point number from an external source over serial (its a PIC giving a voltage reading as an ASCII string output)

It works great but I am having difficulty finding a way to display the data to a set number of decimal places.

I have tried changing my indicator to a number of different display formats, but they all have issues with certain values.

For example, if my incoming string reads "1.123" and I set my display format to floating point with 3 digits of precision, don't hide trailing zeros, it works perfectly and shows "1.123" on my indicator. If the incoming string reads "1.023" it then displays "1.0230" on my indicator, I assume that it doesn't count the first zero as a digit. If I hide trailing zeros then it works with either of the above examples but if the string reads "1.100" then I just get "1.1" on my indicator. Either way the number of digits on my indicator changes according to the data coming in.

I just want it to show 3 decimal places, so either "1.123", "1.023" or "1.100" depending on the input string. Is there any way to fix it like this? I don't want the display to keep changing the number of digits after the decimal point.

Thanks

Link to comment

Hiya,

Just had a play with this in lv 8.6.1, the following setting for the display format (right click on the indicator, then select "Display format") should do what you want:

post-14639-1239467007.png?width=400

This does assume you're using a "numeric" indicator to display your data...

Hope that helps

Paul

Link to comment

Thanks for the reply.

I had tried it set like that, and was getting the data back as I described in the original post. However, I just tried with a new VI as a test and it works fine.

I went back to the original VI and checked all the settings, which were the same, but that was still adding zeros on the end when there was a leading zero (ie. "1.023" would read "1.0230")

I went into the advanced editing mode and found that on the new VI it had "%.3f" as the format string but on the original it had "%_3f". I changed it manually and it works perfectly now, not sure what caused that!

Thanks anyway

Link to comment

QUOTE (postformac @ Apr 11 2009, 09:50 AM)

I went back to the original VI and checked all the settings, which were the same, but that was still adding zeros on the end when there was a leading zero (ie. "1.023" would read "1.0230")

Check "Hide Trailing zeros" in the menu shown above in another post.

Neville.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.