ladybird/Libraries/LibWeb/CSS/Number.cpp
Callum Law bc2ca96f50 LibWeb: Make signature of CSS::{Percentage,Number}::to_string consistent
By making this consistent with the other numeric data type classes we
can simplify cases where we are dealing with variants containing these
types.
2025-08-11 17:10:04 +01:00

25 lines
607 B
C++

/*
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Math.h>
#include <LibWeb/CSS/Number.h>
namespace Web::CSS {
String Number::to_string(SerializationMode) const
{
if (m_type == Type::IntegerWithExplicitSign)
return MUST(String::formatted("{:+}", m_value));
if (m_value == AK::Infinity<double>)
return "infinity"_string;
if (m_value == -AK::Infinity<double>)
return "-infinity"_string;
if (isnan(m_value))
return "NaN"_string;
return MUST(String::formatted("{:.5}", m_value));
}
}