Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
FormatNumber.h File Reference
#include <cmath>
#include <cstdint>
#include <format>
#include <string>
Include dependency graph for FormatNumber.h:
This graph shows which files directly or indirectly include this file:

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

std::string donner::detail::FormatNumberForSVG (double value)
 Format a single double into the minimum-length round-trippable decimal form.

Function Documentation

◆ FormatNumberForSVG()

std::string donner::detail::FormatNumberForSVG ( double value)
inline

Format a single double into the minimum-length round-trippable decimal form.

  • Integer-valued finite doubles (e.g. 10.0, -3.0) are cast to int64_t and formatted without a decimal point or scientific notation.
  • All other doubles use std::format's {} default specifier, which per C++20 [format.string.std] emits the shortest decimal representation that round-trips through std::from_chars. The {:g} specifier was tried and rejected — it defaults to 6-significant-digit precision, which drops accuracy for values like tan(π/6) = 0.57735026918962562.

Used by toSVGTransformString, Path::toSVGPathData, and Length::toRcString().