Division by 10 easy?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Division by 10 easy?

Post by Jan Lichtenbelt »

I have a simple counter from 1 to 20. But I need the counter diviede by 10. Counter is A_byte and the 10th part is A_real. The simulation works correctly. But the microchip has different ideas about this 'problem'. All numbers are correct, except A_byte=14 and A_real should be 1.4. The reality is, see picture
Counter_V1.jpg
Counter_V1.jpg (165.14 KiB) Viewed 3635 times
How is this possible?
Test_Counter_V1.fcfx
(9.13 KiB) Downloaded 206 times
Kind regards

Jan

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Division by 10 easy?

Post by Jan Lichtenbelt »

In the meanwhile I found the solution. All real numbers have positive rounding errors, while 1.4 has been calculated with an negative error with results 1.399...... The 3 lift characters will result into 1.3 instead of 1.4

Kind regards

Jan

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Division by 10 easy?

Post by Steve »

Hi Jan,

If you just want to display the divided number rather than do any maths on it, then you could do something like this:

1) convert the integer to a string:

Code: Select all

value_as_string = ToString$(my_int_value)
2) display the first part of the string:

Code: Select all

Left$(value_as_string, Length$(value_as_string)-1)
3) display a "."


4) display the last digit:

Code: Select all

Right$(value_as_string, 1)
Regards,
Steve.

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Division by 10 easy?

Post by AbhijitR »

Hello! Jan

Many thanks for this post, some what life saving for me.
Jan Lichtenbelt wrote:In the meanwhile I found the solution. All real numbers have positive rounding errors, while 1.4 has been calculated with an negative error with results 1.399...... The 3 lift characters will result into 1.3 instead of 1.4
Any idea how to round off the answer 12.3 to 12 and 12.6 to 13, I think to round off to the nearest value before and after 0.5

Thank you again.

Regards
Abhi

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Division by 10 easy?

Post by medelec35 »

AbhijitR wrote: Any idea how to round off the answer 12.3 to 12 and 12.6 to 13, I think to round off to the nearest value before and after 0.5
Hi Abhi,
I believe the round() function will do what you are after.
If you open a calculation box, then select fx, you can scroll down to round().
Martin

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Division by 10 easy?

Post by AbhijitR »

Hi! Martin
medelec35 wrote: If you open a calculation box, then select fx, you can scroll down to round().
No exaggeration, you are more or less WIKI for FC, thank you once again for that quick reply.

Regards
Abhi

Post Reply