ICU-5152 Remove broken uprv_dtostr function, and create a better ChoiceFormat::dtos function.
X-SVN-Rev: 19525
This commit is contained in:
parent
7bc8795cf7
commit
786c654db5
@ -1,42 +1,13 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2001-2005, International Business Machines
|
||||
* Copyright (C) 2001-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#include "cstring.h"
|
||||
#include "ustrfmt.h"
|
||||
#include <stdio.h>
|
||||
|
||||
U_CAPI char* U_EXPORT2
|
||||
uprv_dtostr(double value, char *buffer, int32_t maximumDigits,UBool fixedPoint)
|
||||
{
|
||||
char *itrPtr = buffer + 1; /* skip '-' or a number before the decimal */
|
||||
char *startPtr;
|
||||
|
||||
sprintf(buffer,"%f",value);
|
||||
|
||||
/* Find the decimal point.
|
||||
Some unusal machines use a comma when the system locale changes
|
||||
*/
|
||||
while (isalnum(*itrPtr)) {
|
||||
itrPtr++;
|
||||
}
|
||||
*itrPtr = '.';
|
||||
|
||||
/* truncate trailing zeros, except the one after '.' */
|
||||
startPtr = itrPtr + 1;
|
||||
itrPtr = uprv_strchr(startPtr, 0);
|
||||
while(--itrPtr > startPtr){
|
||||
if(*itrPtr == '0'){
|
||||
*itrPtr = 0;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/***
|
||||
* Fills in a UChar* string with the radix-based representation of a
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2001-2005, International Business Machines
|
||||
* Copyright (C) 2001-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
@ -10,8 +10,6 @@
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
U_CAPI char* U_EXPORT2
|
||||
uprv_dtostr(double value, char *buffer, int32_t maximumDigits,UBool fixedPoint);
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
uprv_itou (UChar * buffer, int32_t capacity, uint32_t i, uint32_t radix, int32_t minwidth);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
uprv_dtostr(value, temp, 3, TRUE);
|
||||
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 = '.';
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user