AK: Add float support for JsonValue and JsonObjectSerializer

This commit is contained in:
Vrins 2022-03-06 13:18:26 +01:00 committed by Andreas Kling
parent ae1cd4b448
commit 73ade62d4f
Notes: sideshowbarker 2024-07-17 17:46:31 +09:00
2 changed files with 13 additions and 3 deletions

View file

@ -170,6 +170,16 @@ public:
}
#ifndef KERNEL
ErrorOr<void> add(StringView key, float value)
{
TRY(begin_item(key));
if constexpr (IsLegacyBuilder<Builder>)
TRY(m_builder.try_appendff("{}", value));
else
TRY(m_builder.appendff("{}", value));
return {};
}
ErrorOr<void> add(StringView key, double value)
{
TRY(begin_item(key));

View file

@ -101,12 +101,12 @@ public:
unsigned to_uint(unsigned default_value = 0) const { return to_u32(default_value); }
u32 to_u32(u32 default_value = 0) const { return to_number<u32>(default_value); }
u64 to_u64(u64 default_value = 0) const { return to_number<u64>(default_value); }
#if !defined(KERNEL)
double to_double(double default_value = 0) const
float to_float(float default_value = 0) const
{
return to_number<double>(default_value);
return to_number<float>(default_value);
}
double to_double(double default_value = 0) const { return to_number<double>(default_value); }
#endif
FlatPtr to_addr(FlatPtr default_value = 0) const