[Feature] New format specifier '%w' for Dimension values
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[Feature] New format specifier '%w' for Dimension values
Hello!
I propose to add a new format specifier '%w' for Dimension values. It's a mixture between the standard formats '%f' and '%g', and it works like '%f', except that it removes trailing zeros like '%g', but without the other properties of '%g'. That way, it'd be possible to have, e.g., a dimension specifier '%.2w', which would print at most 2 decimals after dot, but cut away any trailing zeros. The problem with '%.2g' is that it gives 2 significant digits, not 2 digits after dot like '%.2f' (and the newly proposed '%.2w'). I use this kind of formatting style a lot (i.e. fixed number of decimals, but trailing zeros removed), so I wrote a small patch that adds this kind of new format specifier. The picture below shows the differences between the 3 formats, I hope it makes my explanation more clear!
I propose to add a new format specifier '%w' for Dimension values. It's a mixture between the standard formats '%f' and '%g', and it works like '%f', except that it removes trailing zeros like '%g', but without the other properties of '%g'. That way, it'd be possible to have, e.g., a dimension specifier '%.2w', which would print at most 2 decimals after dot, but cut away any trailing zeros. The problem with '%.2g' is that it gives 2 significant digits, not 2 digits after dot like '%.2f' (and the newly proposed '%.2w'). I use this kind of formatting style a lot (i.e. fixed number of decimals, but trailing zeros removed), so I wrote a small patch that adds this kind of new format specifier. The picture below shows the differences between the 3 formats, I hope it makes my explanation more clear!
Last edited by aapo on Fri Feb 18, 2022 2:12 pm, edited 2 times in total.
Re: [Feature proposal] New format specifier '%w' for Dimension values
Here is the pull request, test away please! https://github.com/FreeCAD/FreeCAD/pull/5401
Re: [Feature proposal] New format specifier '%w' for Dimension values
Here is a test case, where all dimension values have the same format specifier '%.2w'. Note that there are values like "50", "36.6", "0.5", which all have one or more trailing zeros removed.
Re: [Feature proposal] New format specifier '%w' for Dimension values
IMHO this would be a handy feature!
Thanks for the pull request.
BTW your bear face gave me a good mood
Thanks for the pull request.
BTW your bear face gave me a good mood
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: [Feature proposal] New format specifier '%w' for Dimension values
git commit 253817e3aapo wrote: ↑Thu Jan 20, 2022 4:26 pm Here is the pull request, test away please! https://github.com/FreeCAD/FreeCAD/pull/5401
Thank you!
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: [Feature proposal] New format specifier '%w' for Dimension values
Time for documentation guys.
Re: [Feature proposal] New format specifier '%w' for Dimension values
Thanks for merging!
Re: [Feature proposal] New format specifier '%w' for Dimension values
https://wiki.freecadweb.org/TechDraw_Le ... Formatting looks like a good candidate to me. Especially because you introduced a specifier which isn't C standard, hence not covered by current doc.