Remove trailing zeros in TechDraw dimensions

Discussions about the development of the TechDraw workbench
SIXe
Posts: 11
Joined: Sat Mar 16, 2019 3:10 pm

Remove trailing zeros in TechDraw dimensions

Postby SIXe » Sun Mar 17, 2019 12:02 pm

How to remove trailing zeros in TechDraw dimensions? That would lead to cleaner and more readable drawings. Searching the forum I came about the thread Dimension Decimal Places, which suggests to use the format %.g, but that doesn't seem to do the trick.

Example:

Image

OS: Debian GNU/Linux buster/sid
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.
Build type: Release
Python version: 3.7.2+
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
wandererfan
Posts: 2389
Joined: Tue Nov 06, 2012 5:42 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby wandererfan » Sun Mar 17, 2019 1:42 pm

SIXe wrote:
Sun Mar 17, 2019 12:02 pm
How to remove trailing zeros in TechDraw dimensions? That would lead to cleaner and more readable drawings. Searching the forum I came about the thread Dimension Decimal Places, which suggests to use the format %.g, but that doesn't seem to do the trick.
Check your Preferences. If you have "Use Global Decimals" ticked, the system-wide setting overrides the FormatSpec on an individual Dimension.
gFormatTrailingZeroes.png
gFormatTrailingZeroes.png (62.86 KiB) Viewed 183 times


OS: Linux Mint 19
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16093 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 690774c0effe4fd7b8d2b5e2fb2b8c8d145e21ce
Python version: 2.7.15rc1
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Canada (en_CA)
SIXe
Posts: 11
Joined: Sat Mar 16, 2019 3:10 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby SIXe » Sun Mar 17, 2019 1:54 pm

wandererfan wrote:
Sun Mar 17, 2019 1:42 pm
Check your Preferences. If you have "Use Global Decimals" ticked, the system-wide setting overrides the FormatSpec on an individual Dimension.
That's it. %.g works now. Thanks a lot. One question, though: How to specify the default FormatSpec so I don't have to change the FormatSpec every single time?
wandererfan
Posts: 2389
Joined: Tue Nov 06, 2012 5:42 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby wandererfan » Sun Mar 17, 2019 8:30 pm

SIXe wrote:
Sun Mar 17, 2019 1:54 pm
How to specify the default FormatSpec so I don't have to change the FormatSpec every single time?
:oops: :oops: :oops:
That is crossed off on the TODO list, but was never implemented.

Will fix that next batch of changes.
Jee-Bee
Posts: 1630
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Remove trailing zeros in TechDraw dimensions

Postby Jee-Bee » Sun Mar 17, 2019 8:37 pm

Would that mean you want to implement an kind of remove automatic trailing zeros? And what to do with round of values?

13.60 = 13.6
and 5.8985 = 5.90 = 5.9
SIXe
Posts: 11
Joined: Sat Mar 16, 2019 3:10 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby SIXe » Sun Mar 17, 2019 8:43 pm

wandererfan wrote:
Sun Mar 17, 2019 8:30 pm
Will fix that next batch of changes.
Great. Thanks.
wandererfan
Posts: 2389
Joined: Tue Nov 06, 2012 5:42 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby wandererfan » Sun Mar 17, 2019 8:47 pm

Jee-Bee wrote:
Sun Mar 17, 2019 8:37 pm
Would that mean you want to implement an kind of remove automatic trailing zeros? And what to do with round of values?

13.60 = 13.6
and 5.8985 = 5.90 = 5.9
No, just a way to specify that you want to use "%.g" instead of "%.[AlternateDecimals]f" as your default value for FormatSpec.

IIRC, "%.g" just removes trailing zeroes, so
13.60 would be 13.6
5.8985 would be 5.8985
SIXe
Posts: 11
Joined: Sat Mar 16, 2019 3:10 pm

Re: Remove trailing zeros in TechDraw dimensions

Postby SIXe » Sun Mar 17, 2019 8:52 pm

Jee-Bee wrote:
Sun Mar 17, 2019 8:37 pm
Would that mean you want to implement an kind of remove automatic trailing zeros?
An option to specify a *default* FormatSpec. So the user can choose to display a fixed number, remove trailing zeros or any other supported format spec.
Jee-Bee wrote:
Sun Mar 17, 2019 8:37 pm
And what to do with round of values?
That's up to the used FormatSpec. Rounding has nothing to do with this question/feature as far as I understand.
reox
Posts: 476
Joined: Sat Aug 13, 2016 10:06 am

Re: Remove trailing zeros in TechDraw dimensions

Postby reox » Mon Mar 18, 2019 7:48 am

Rounding is a thing with the g formatter:

Code: Select all

>>> '%.2g' % (23.12345)
'23'
>>> '%.3g' % (23.12345)
'23.1'
>>> '%.4g' % (23.12345)
'23.12'
>>> '%.5g' % (23.12345)
'23.123'
>>> '%.5g' % (233.12345)
'233.12'
>>> '%.5g' % (233.999)
'234'
the number gives the precision in decimals shown totally.
Just be aware, that larger numbers are shown in exponent representation:

Code: Select all

>>> '%.5g' % 123456.234
'1.2346e+05'