Skip to content

Grisu: trailing zero with fixed, precision=0, and showpoint #1417

Closed
@planet36

Description

When printing in fixed notation with precision=0 and showpoint , there is a trailing zero when Grisu is enabled.

Using g++ 9.2.1 and libfmt master branch (9108b25)

The following code illustrates this

#include <fmt/format.h>
#include <iostream>

int main()
{
	std::cout << "FMT_VERSION=" << FMT_VERSION << '\n';
	std::cout << "FMT_GCC_VERSION=" << FMT_GCC_VERSION << '\n';
#ifdef FMT_USE_GRISU
	std::cout << "FMT_USE_GRISU=" << FMT_USE_GRISU << '\n';
#else
	std::cout << "FMT_USE_GRISU not defined\n";
#endif

	double x = 123.0;
	int precision = 0;

	std::cout.precision(precision);

	std::cout << "cout: " << std::showpoint << std::fixed << x << '\n';
	std::cout << "fmt:  " << fmt::format("{:#.{}f}", x, precision) << '\n';

	return 0;
}

Outputs:

FMT_VERSION=60001
FMT_GCC_VERSION=902
FMT_USE_GRISU=1
cout: 123.
fmt:  123.0

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions