From ddac3cfb6693a77b5662c123a876755f9dfe47e1 Mon Sep 17 00:00:00 2001 From: Ryan Fox Date: Mon, 24 Jun 2013 15:39:00 -0400 Subject: [PATCH 1/4] Add the ability to create a string from a double. --- goo/GooString.cc | 8 ++++++++ goo/GooString.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/goo/GooString.cc b/goo/GooString.cc index d35161d..5a650fe 100644 --- a/goo/GooString.cc +++ b/goo/GooString.cc @@ -253,6 +253,14 @@ GooString *GooString::fromInt(int x) { return new GooString(p, len); } +GooString *GooString::fromDouble(double x, int prec) { + char buf[256]; + char *p; + int len; + formatDouble(x, buf, sizeof(buf), prec, gFalse, &p, &len); + return new GooString(p, len); +} + GooString *GooString::format(const char *fmt, ...) { va_list argList; GooString *s; diff --git a/goo/GooString.h b/goo/GooString.h index b24051b..ac89054 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -66,8 +66,9 @@ public: // Concatenate two strings. GooString(GooString *str1, GooString *str2); - // Convert an integer to a string. + // Convert a number to a string. static GooString *fromInt(int x); + static GooString *fromDouble(double x, int precision); // Create a formatted string. Similar to printf, but without the // string overflow issues. Formatting elements consist of: -- 1.7.9.5