From 0a0e8f36ebe4cb24a611f2707304d284fe4a9a90 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Mon, 14 Nov 2022 04:30:14 -0800 Subject: [PATCH] add floats to string builder --- core/strings/builder.odin | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/strings/builder.odin b/core/strings/builder.odin index 0386431f1..e58406ee6 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -299,6 +299,13 @@ write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false return } +// writes a f64 value into the builder, returns the written amount of characters +write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int) -> (n: int) { + buf: [384]byte + s := strconv.append_float(buf[:], f, fmt, prec, bit_size) + return write_string(b, s) +} + // writes a u64 value `i` in `base` = 10 into the builder, returns the written amount of characters write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) { buf: [32]byte