Trailing zeros

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
CrashedAgain
Posts: 187
Joined: Wed Jan 15, 2020 8:39 pm

Trailing zeros

Post by CrashedAgain »

Is there a setting to suppress trailing zeros (other than arbitrarily changing the dimension format)?

{Edit} Received no reply, submitted as feature request. https://tracker.freecadweb.org/view.php?id=4485
asegura
Posts: 16
Joined: Sat Jan 23, 2021 11:43 pm

Re: Trailing zeros

Post by asegura »

Hi,

I has having a similar issue, I also think traling zeros like in 10.00 are ugly. I found that under Preferences / TechDraw / Dimensions there is a control for "Number of decimals" which defaults to 2.

You can change it to zero and you will see "25" instead of "25.00" in a dimension. But the problem is you will lose decimal places when needed.

I think a better way is to change the number format from "f" to "g" (this is like printf). So, if the format spec is changed from "%.2f" to "%.6g" then decimals after the dot will only appear if needed (up to 6 significant digits) and there will be no trailing zeros.

Then for example, you would see values like 12, 20.5, 5.25.

My suggestion for the feature request would be to add a global format specifier to the preferences section I mentioned. Not just a "number of decimal places", but a full format string which will be used by default. Or alternatively, if a format string is too programmer-oriented, a selector for "Fixed" [f] or "Dynamic" [g] decimals by default. This currently only uses "f", but should also alow "g".
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: Trailing zeros

Post by aapo »

asegura wrote: Sun Jan 24, 2021 10:39 am My suggestion for the feature request would be to add a global format specifier to the preferences section I mentioned. Not just a "number of decimal places", but a full format string which will be used by default. Or alternatively, if a format string is too programmer-oriented, a selector for "Fixed" [f] or "Dynamic" [g] decimals by default. This currently only uses "f", but should also alow "g".
This already exists, it is "Preferences->TechDraw->Advanced->Dimension Format", where you can put "%.2g" or any other format specifier, which will be used by default (i.e. any new dimension created will have this format specifier). I'm not sure why it's grouped in "Advanced" tab and not "Dimensions" tab.

One thing that is missing is a format specifier that would mimic the old FreeCAD v 0.18 behavior. With the old version, it was possible to control the number of decimals (%f) and get rid of trailing zeros (%g) at the same time. So, it was kind of a mix between %f and %g. The problem with %g is that you cannot control the number of decimals, but number of significant figures instead. This has been that way for decades, it's the original and current behavior of the std C function printf(). There's probably an old, good reason for this behavior, but for FreeCAD I've been thinking about adding a non-standard format specifier, e.g. "%w", that would mimic the old v 0.18 behavior.
asegura
Posts: 16
Joined: Sat Jan 23, 2021 11:43 pm

Re: Trailing zeros

Post by asegura »

Great, thanks! I went through preferences but missed that.

I set it to "%.6g" as a safe default. (%.2g will produce "1e+02" instead of "100")
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: Trailing zeros

Post by aapo »

asegura wrote: Sun Jan 24, 2021 4:58 pm Great, thanks! I went through preferences but missed that.

I set it to "%.6g" as a safe default. (%.2g will produce "1e+02" instead of "100")
It's also possible to put "%g" there, it'd give you as many significant digits as possible, but still cut the trailing zeros away. The problem is that if you'll have a value like 3.141592653589, it's gonna show you all of the decimals available, which is pretty ugly.
CrashedAgain
Posts: 187
Joined: Wed Jan 15, 2020 8:39 pm

Re: Trailing zeros

Post by CrashedAgain »

Excellent! Just what I wanted.
Never knew about "g" instead of "f".
Is there a list somewhere of what can be used?
aapo
Posts: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: Trailing zeros

Post by aapo »

CrashedAgain wrote: Sun Jan 24, 2021 7:22 pm Is there a list somewhere of what can be used?
https://en.wikipedia.org/wiki/Printf_format_string

With the TechDraw Dimensions, you are restricted to floating-point numbers, i.e. f, g, and e. But I thing that most of the flags and field stuff might work. If not, it can most likely be fixed! :D
CrashedAgain
Posts: 187
Joined: Wed Jan 15, 2020 8:39 pm

Re: Trailing zeros

Post by CrashedAgain »

Thanks
Post Reply