How to use inches in expression function

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
bananaphone
Posts: 1
Joined: Sun Jun 20, 2021 7:34 pm

How to use inches in expression function

Post by bananaphone »

The ceil function isn't working as expected for me. It seems to have something to do with the unit.

For example, this expression
=ceil(40.1) correctly resolves to 41

However this resolves to some weird value:
=ceil(40.1 in) incorrectly resolves to 40.12 in

Ultimately I'm trying to round an expression up to the nearest 1/8th of an inch. Normally I could do that like this:
=ceil( someValue / (1/8) ) * (1/8)

But if someValue is in inches, it doesn't work correctly.

What am I missing here? Thanks in advance!
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: How to use inches in expression function

Post by GeneFC »

It is clear that the ceiling is being calculated on the metric equivalent of the entry value.

Probably could be considered a bug, or at least a missing function.

FreeCAD does all internal calculations in metric, so a special function would be needed to calculate floor and ceiling for dimensions in other units.

Most linear and analytic functions work correctly in any units, but floor and ceiling are not linear nor analytic.

Gene
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use inches in expression function

Post by chrisb »

You may need something like

Code: Select all

ceil(someValue*2.54 / (1/8)) * (1/8)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to use inches in expression function

Post by openBrain »

chrisb wrote: Mon Jun 21, 2021 6:15 am You may need something like

Code: Select all

ceil(someValue*2.54 / (1/8) * (1/8))
One of the closing parentheses is misplaced. ;)
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use inches in expression function

Post by chrisb »

openBrain wrote: Mon Jun 21, 2021 7:39 am One of the closing parentheses is misplaced. ;)
Thanks for the hint. I have corrected my post above.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply