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
Kind regards
Jan
How is this possible?Division by 10 easy?
Moderator: Benj
- 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:
- 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?
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
Kind regards
Jan
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Division by 10 easy?
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:
2) display the first part of the string:
3) display a "."
4) display the last digit:
Regards,
Steve.
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)
Code: Select all
Left$(value_as_string, Length$(value_as_string)-1)
4) display the last digit:
Code: Select all
Right$(value_as_string, 1)
Steve.
- 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?
Hello! Jan
Many thanks for this post, some what life saving for me.
Thank you again.
Regards
Abhi
Many thanks for this post, some what life saving for me.
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.5Jan 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
Thank you again.
Regards
Abhi
-
- 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?
Hi Abhi,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
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
- 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?
Hi! Martin
Regards
Abhi
No exaggeration, you are more or less WIKI for FC, thank you once again for that quick reply.medelec35 wrote: If you open a calculation box, then select fx, you can scroll down to round().
Regards
Abhi