From 2690c07220601d7d8c69b18bb5017a2cd234aca3 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Sun, 29 Jun 2025 12:37:07 +0100 Subject: [PATCH] Display integers with no decimal points --- cclox_src/scanner/object.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cclox_src/scanner/object.cc b/cclox_src/scanner/object.cc index 864d1a1..dc14f91 100644 --- a/cclox_src/scanner/object.cc +++ b/cclox_src/scanner/object.cc @@ -1,4 +1,5 @@ #include "object.hh" +#include #include std::string Object::to_string() { @@ -16,7 +17,12 @@ std::string Object::to_string() { } case ObjectType::NUMBER: { double val = std::get(value); - return std::to_string(val); + std::string output{std::to_string(val)}; + if (val == ((int)val)) { + size_t decimal_index{output.find(".")}; + output = output.substr(0, decimal_index); + } + return output; } } }