diff options
Diffstat (limited to 'Build/source/libs/icu-xetex/i18n/choicfmt.cpp')
-rw-r--r-- | Build/source/libs/icu-xetex/i18n/choicfmt.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Build/source/libs/icu-xetex/i18n/choicfmt.cpp b/Build/source/libs/icu-xetex/i18n/choicfmt.cpp index eeac7f381ca..b9caa9a3b9c 100644 --- a/Build/source/libs/icu-xetex/i18n/choicfmt.cpp +++ b/Build/source/libs/icu-xetex/i18n/choicfmt.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2004, International Business Machines Corporation and * +* Copyright (C) 1997-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -31,9 +31,10 @@ #include "unicode/numfmt.h" #include "unicode/locid.h" #include "cpputils.h" -#include "ustrfmt.h" #include "cstring.h" #include "putilimp.h" +#include <stdio.h> +#include <float.h> // ***************************************************************************** // class ChoiceFormat @@ -210,9 +211,33 @@ UnicodeString& ChoiceFormat::dtos(double value, UnicodeString& string) { - char temp[256]; + /* Buffer to contain the digits and any extra formatting stuff. */ + char temp[DBL_DIG + 16]; + char *itrPtr = temp; + char *startPtr; + + sprintf(temp, "%.*f", DBL_DIG, value); + + /* Find and convert the decimal point. + Using setlocale on some machines will cause sprintf to use a comma for certain locales. + */ + while (*itrPtr && (*itrPtr == '-' || isdigit(*itrPtr))) { + itrPtr++; + } + if (*itrPtr) { + *itrPtr = '.'; + } - uprv_dtostr(value, temp, 3, TRUE); + /* remove trailing zeros, except the one after '.' */ + startPtr = itrPtr + 1; + itrPtr = uprv_strchr(startPtr, 0); + while(--itrPtr > startPtr){ + if(*itrPtr == '0'){ + *itrPtr = 0; + }else{ + break; + } + } string = UnicodeString(temp, -1, US_INV); /* invariant codepage */ return string; } |