# Division error

## Recommended Posts

I am trying to move the decimal point of a counter value by dividing by 1000.  I think this is a binary issue because when the result reaches 32 it goes to -32 and decrements. This is  back and forth from negative to positive.  How do I work around this? I added a picture of my block to see.

##### Share on other sites

• MVP 2022

Make sure you're not overflowing your Memory Integer. Just to be sure, use MLs instead and see if the situation improves.

##### Share on other sites

Nope, no workie workie using ML's.

##### Share on other sites

An MI is a signed value from 32767 to -32768.  When you divide by 1000, I would expect to see what you are seeing due to word wrap to a negative value when the value gets larger than 32767 (accessing the sign bit/MSB).  As said by Flex727, you will probably need to utilize one of the double word formats ML, DW etc. to allow values large enough to not roll over the word.  You could also cascade counters by making one counter count to 1000 and counting the number  times it gets there with a second counter.

##### Share on other sites

• MVP 2022

bbird suggests a good workaround. I fully understand the issues with binary-decimal conversion, but I've personally never seen the problem you experiencing. I would request that you post the rest of your code and let's take a look.

##### Share on other sites

You can also try converting the value from the counter to a Float before dividing by 1000 and placing the result in a float as below.  MI 3 can be substituted for your counter value.  MF1 will be = (MI3/1000)

Edited by bbird
wont' let me delete incorrect logic image
##### Share on other sites

• MVP 2022

Hi Visco and all,

I'm not completely sure what you're trying to do here, Visco, as your input being an MI is a bit self-regulating for possible amounts.  Doesn't my screenshot below do it easily?  But if you put 1000 into MI0, your result here will be 1, without any dec point.  So this raises my question of what exactly are you trying to do with the result?  Is it simply maths, displaying etc?

cheers,

Aus

##### Share on other sites

On 5/6/2017 at 5:01 AM, Ausman said:

Hi Visco and all,

I'm not completely sure what you're trying to do here, Visco, as your input being an MI is a bit self-regulating for possible amounts.  Doesn't my screenshot below do it easily?  But if you put 1000 into MI0, your result here will be 1, without any dec point.  So this raises my question of what exactly are you trying to do with the result?  Is it simply maths, displaying etc?

cheers,

Aus

I am trying to display 1000's of an inch. like 123.375"

##### Share on other sites

Visco

leave your number as an integer (whole number, no decimal) in the logic,

apply the decimal point in the display settings......

JohnR

##### Share on other sites

• MVP 2022

Exactly, JohnR.

Visco, remember my comment about sometimes things can be simple, sometimes complex.  A major part of programming is pinning down exactly what you need to achieve, and then finding the easiest way to do it.  I often put all my known methods into the washing machine called the brain, and ages later I still end up with something not even considered in the first place!  It is a constant learning curve.

cheers,

Aus

##### Share on other sites

On 5/8/2017 at 1:24 PM, JohnR said:

Visco

leave your number as an integer (whole number, no decimal) in the logic,

apply the decimal point in the display settings......

JohnR

I added the decimal point in the display and now it just rolls over at 37.

##### Share on other sites

On 5/5/2017 at 4:43 PM, bbird said:

You can also try converting the value from the counter to a Float before dividing by 1000 and placing the result in a float as below.  MI 3 can be substituted for your counter value.  MF1 will be = (MI3/1000)

BBird, That worked. Thank you!! Much appreciated

##### Share on other sites

Thanks,

I think Ausman's version will do the same thing more efficiently with one less block, as the conversion is done automatically in the floating point divide block.  Lots of ways to accomplish the same result.  Glad it's working.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×