From 6427cf07c8df85352c2be164a5d18c8c709de193 Mon Sep 17 00:00:00 2001 From: pmqueiroz Date: Sun, 1 Dec 2024 23:36:03 -0300 Subject: [PATCH] fix: prevent big nums to be printed as scientific notation --- interpreter/interpreter.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index d72329e..f4d4dfa 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -70,13 +70,16 @@ func Interpret(statement ast.Statement, env *environment.Environment) error { var output string - if str, ok := value.(string); ok { - str = strings.ReplaceAll(str, "\\n", "\n") - str = strings.ReplaceAll(str, "\\t", "\t") - str = strings.ReplaceAll(str, "\\\"", "\"") - str = strings.ReplaceAll(str, "\\\\", "\\") - output = fmt.Sprint(str) - } else { + switch v := value.(type) { + case string: + v = strings.ReplaceAll(v, "\\n", "\n") + v = strings.ReplaceAll(v, "\\t", "\t") + v = strings.ReplaceAll(v, "\\\"", "\"") + v = strings.ReplaceAll(v, "\\\\", "\\") + output = fmt.Sprint(v) + case float64: + output = fmt.Sprintf("%.f", v) + default: output = fmt.Sprint(value) } channel.Write([]byte(output))