# Mm to inch error

**URL:** <https://forums.maslowcnc.com/t/mm-to-inch-error/1714>\
**Category:** Software\
**Created:** [December 31, 2017, 4:07am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714 "2017-12-31T04:07:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Pollock](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@Bryan\_Pollock](https://forums.maslowcnc.com/u/Bryan_Pollock)\
**Post date:** [December 31, 2017, 4:07am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/1 "2017-12-31T04:07:27Z")

</div>

This may have been addressed before but I couldn’t find anything.

I’m using Ground Control 1.0, when I change the “Distance to Move” number in inches say to 20 and switch to mm it comes back with 500 instead of 508. Is there some floating point error some where?

---

<div class="post-metadata">

**Author:** ![dlang](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/dlang/32/859_2.png) [@dlang](https://forums.maslowcnc.com/u/dlang)\
**Post date:** [December 31, 2017, 4:24am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/2 "2017-12-31T04:24:29Z")

</div>

that sounds like there’s an int used when it should be a float (we’ve seen that  
before)

---

<div class="post-metadata">

**Author:** ![Bryan\_Pollock](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@Bryan\_Pollock](https://forums.maslowcnc.com/u/Bryan_Pollock)\
**Post date:** [December 31, 2017, 4:35am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/3 "2017-12-31T04:35:31Z")

</div>

I found the error in the [frontPage.py](http://frontPage.py). The newUnits divide and multiply by 25 instead of 25.4

def onUnitsSwitch(self, callback, newUnits):  
self.units = newUnits  
INCHESTOMM = 1/25.4  
MMTOINCHES = 25.4

```
    if newUnits == "INCHES":
        self.data.gcode_queue.put('G20 ')
        self.moveDistInput.text = str(float(self.moveDistInput.text)/25)
        self.data.tolerance = 0.020
    else:
        self.data.gcode_queue.put('G21 ')
        self.moveDistInput.text = str(float(self.moveDistInput.text)*25)
        self.data.tolerance = 0.5
```

---

<div class="post-metadata">

**Author:** ![dlang](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/dlang/32/859_2.png) [@dlang](https://forums.maslowcnc.com/u/dlang)\
**Post date:** [December 31, 2017, 4:50am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/4 "2017-12-31T04:50:37Z")

</div>

good catch

do you want to make a pull request for this fix or just have one of the regulars  
submit it?

---

<div class="post-metadata">

**Author:** ![Bryan\_Pollock](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@Bryan\_Pollock](https://forums.maslowcnc.com/u/Bryan_Pollock)\
**Post date:** [December 31, 2017, 5:06am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/5 "2017-12-31T05:06:59Z")

</div>

I had to add the ‘%.2f’ to format the string or else you get overrun of numbers. I’m not real confident in my programming abilities so I would feel better having on of the regulars fix it.

This is what I did.

def onUnitsSwitch(self, callback, newUnits):  
self.units = newUnits  
INCHESTOMM = 1/25.4  
MMTOINCHES = 25.4

```
    if newUnits == "INCHES":
        self.data.gcode_queue.put('G20 ')
        self.moveDistInput.text = str('%.2f'%(float(self.moveDistInput.text)/25.4))
        self.data.tolerance = 0.0
    else:
        self.data.gcode_queue.put('G21 ')
        self.moveDistInput.text = str('%.2f'%(float(self.moveDistInput.text)*25.4))
        self.data.tolerance = 0.0
```

---

<div class="post-metadata">

**Author:** ![dlang](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/dlang/32/859_2.png) [@dlang](https://forums.maslowcnc.com/u/dlang)\
**Post date:** [December 31, 2017, 5:35am UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/6 "2017-12-31T05:35:05Z")

</div>

That looks like the right fix to me.

---

<div class="post-metadata">

**Author:** ![bar](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/bar/32/10_2.png) [@bar](https://forums.maslowcnc.com/u/bar)\
**Post date:** [December 31, 2017, 7:18pm UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/7 "2017-12-31T19:18:56Z")

</div>

This is my fault. I set it to 25 instead of 25.4 there because I figured when switching from inches to mm mode for moving the machine around we would probably rather have nice round numbers. I liked that the defaults were 4 inches and 100mm. I’m more than happy to have it by 25.4 if we decide the other way is confusing

---

<div class="post-metadata">

**Author:** ![blurfl](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/blurfl/32/9_2.png) [@blurfl](https://forums.maslowcnc.com/u/blurfl)\
**Post date:** [December 31, 2017, 7:32pm UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/8 "2017-12-31T19:32:57Z")

</div>

> [@bar](#):
>
> I liked that the defaults were 4 inches and 100mm.

I liked that too. I just use this dialog is just for moving around, usually want a nice round number. If I want precision, I can get it after changing the units.

---

<div class="post-metadata">

**Author:** ![vertex](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/vertex/32/972_2.png) [@vertex](https://forums.maslowcnc.com/u/vertex)\
**Post date:** [December 31, 2017, 9:06pm UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/9 "2017-12-31T21:06:07Z")

</div>

To me it makes more sense to have accurate conversions. I don’t fully understand what @bar and @blurfl like about not having accurate conversions though it also makes good sense when round numbers improve ease of use.

It’s a feature, not a bug issue? 🙂  
Or a bug with a nice feature?

---

<div class="post-metadata">

**Author:** ![dlang](https://yyz1.discourse-cdn.com/flex031/user_avatar/forums.maslowcnc.com/dlang/32/859_2.png) [@dlang](https://forums.maslowcnc.com/u/dlang)\
**Post date:** [December 31, 2017, 9:46pm UTC](https://forums.maslowcnc.com/t/mm-to-inch-error/1714/10 "2017-12-31T21:46:21Z")

</div>

I agree that the conversion should be accurate, Having the default be 4 in or  
100mm is reasonable, but having it be off if you type one and convert it is not.
