Fix %g in fmt, and make %v default to %g for floats

This commit is contained in:
gingerBill
2023-12-21 17:05:24 +00:00
parent 509712f771
commit 55f3e99f63
2 changed files with 19 additions and 8 deletions
+7 -2
View File
@@ -2,6 +2,8 @@ package strconv
import "decimal"
import "core:runtime"
Decimal_Slice :: struct {
digits: []byte,
count: int,
@@ -103,8 +105,11 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int)
}
} else {
switch fmt {
case 'e', 'E': decimal.round(d, prec+1)
case 'f', 'F': decimal.round(d, d.decimal_point+prec)
case 'e', 'E':
prec += 1
decimal.round(d, prec)
case 'f', 'F':
decimal.round(d, d.decimal_point+prec)
case 'g', 'G':
if prec == 0 {
prec = 1