Comments (9)
Looks the same as #2155.
from fmt.
I don't think you can express it in a format string directly but you can use the f specifier and then remove trailing zeros and the decimal point.
[As you meant: #2155]((#2155 (comment))
Of course it works, even with printf - I would just like it to be more convenient, as would others.
that it is close to the standard - is very good, but why not extend it, that does not harm the fmt library, if the standard works, but there would still be extensions, everything so far continues to work exactly....
from fmt.
Hi,
i implemented the new type in the current version. Do you want to see the code?
this is an example output for the double value:
double w = -0.00000001;
fmt::print("{{:+.3v}}={:+.3v} {{:+#.3v}}={:+#.3v}\n", w, w);
fmt::print("{{:-.3v}}={:-.3v} {{:-#.3v}}={:-#.3v}\n", w, w);
fmt::print("{{:.3v}}={:.3v} {{:#.3v}}={:#.3v}\n", w, w);
fmt::print("{{:*>12.3v}}={:*>12.3v} {{:#.3v}}={:#.3v}\n", w, w);
output:
{:+.3v}=-0 {:+#.3v}=-0.
{:-.3v}=-0 {:-#.3v}=-0.
{:.3v}=0 {:#.3v}=0.
{:*>12.3v}=***********0 {:#.3v}=0.
from fmt.
should i make a PR to be able to present the enhancements?
from fmt.
No but you can post an example of a user-defined formatter that does this.
from fmt.
As i understand it, i can't define a user-defined formatter for a standard type like double. that's why i integrated the new type for formatting. i only have to add/change about 40 lines. everything existing should work as before.
is there a change that this change can be integrated into the library in an upcoming version?
If not, what are the reasons for this. I would be happy to start a discussion on this.
from fmt.
You can define a custom formatter for this via a wrapper type.
from fmt.
I apologise for being so harsh, I don't want to annoy anyone.
I have understood that and I know how to implement it.
What are the reasons for not including the new format type?
- performance?
- no standard?
- no need?
- no time/resources to implement?
in my use case i sometimes have more than a million double values to format. just to wrap the value in a wrapper type and then edit it in a custom formatter makes no sense and costs unnecessary performance.
the use case is quite common in industry, especially with nc machines, such as milling and turning machines, also 3d printers. it is nc code or gcode. the new format reduces the file size and is more readable.
from fmt.
It is important to maintain compatibility with std::format
and keep the core library small. The extension API is there to support custom, possibly common, formats.
from fmt.
Related Issues (20)
- Does not compile with the FMT_PEDANTIC=ON and FMT_WERROR=ON options HOT 3
- Add support for alternative month format HOT 2
- P3142R0: Printing Blank Lines with println HOT 1
- MSVC errors when importing both fmt and std modules HOT 19
- Cannot use ostream support on fmt 9.x and 10.x HOT 1
- fmt::format_to + FMT_STRING with wide characters fails to compile HOT 1
- Invalid PDB file generated due to MSVC 2017 compatibility code HOT 6
- std::chrono::current_zone() is not meant to return the local time zone HOT 4
- It would be good to have a customizable separator in fmt::group_digits(...) HOT 1
- fmt::styled and fmt::formatter<std::string> parse deactivate colors/termaps HOT 1
- formatting of variant types HOT 3
- FMT_USE_NONTYPE_TEMPLATE_ARGS detection is wrong on trunk HOT 2
- Support for a single `char` separator in `fmt::join()` HOT 1
- Formatting for strings with custom allocators fails to compile HOT 2
- Advice for extending libfmt for GPU support? HOT 2
- xchar.h extra dependencies HOT 1
- cannot use in CUDA (+MSVC) for newest branch master HOT 1
- Question: what's the difference between string-like formatters and where are they defined? HOT 2
- fmt won't let me specialize a formatter to format mixed character types. HOT 2
- `fmt::isnan` triggers floating-point exception for NaN values HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fmt.