Author Topic: Decimal Values  (Read 4422 times)

Offline Emerson Zaionc

  • PLUS+1 User
  • **
  • Posts: 9
  • Karma: +0/-0
Decimal Values
« on: November 24, 2016, 05:26:04 PM »
Hello guys;
Could you answer me if you can use this value in the image described as 'True Value'. I need to work with decimal values and I do not know how to do it. Today I'm working with 'False Value', but I need more precision.
Can you help me?

Offline Jakob

  • PLUS+1 Expert
  • ****
  • Posts: 95
  • Karma: +2/-0
Re: Decimal Values
« Reply #1 on: November 25, 2016, 07:57:38 AM »
Hi,
What I usually do is to scale up the value before the division.
Meaning first multiply with 10000 and then divide by 21 (or what ever value you need).

I hope that helps

/Jakob

Offline Emerson Zaionc

  • PLUS+1 User
  • **
  • Posts: 9
  • Karma: +0/-0
Re: Decimal Values
« Reply #2 on: November 25, 2016, 04:00:15 PM »
Could you put a picture as an example?


Offline spittet

  • PLUS+1 Guru
  • *****
  • Posts: 113
  • Karma: +5/-1
Re: Decimal Values
« Reply #3 on: November 25, 2016, 06:51:11 PM »
Taken from your example above :

10/6 = 2 (should be 1.67)

Assuming you want 2 decimal precision, then you should do the following :

10 x 100 = 1000 --> 1000/6 = 166. Then, you need to remember that this number (166) is 1.66 x 100. The next step would be to extract the integer part and the decimal part of this number to have 2 other numbers : 1 and 66. Then, in a text component, you can input the "1" as the integer part and the "66" as the decimal part after the point. to show the real number as "1"."66" .

Remember that you cannot use floating point values in PLUS1. They are all integers.

Also, make sure to use 16-bit or 32-bit data type because the first multiplication (by 100 or 1000) can increase the output a lot and you can fall into an overflow.

Sam
« Last Edit: November 25, 2016, 06:53:05 PM by spittet »