Chromium Code Reviews| Index: base/i18n/number_formatting.cc |
| diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc |
| index a529a84651b9e646261ccfb9a90db5a3115d6b66..986f1ed1f6331b9b607a6fc11115e7c7cba6ea72 100644 |
| --- a/base/i18n/number_formatting.cc |
| +++ b/base/i18n/number_formatting.cc |
| @@ -34,10 +34,15 @@ struct NumberFormatWrapper { |
| } // namespace |
| -static LazyInstance<NumberFormatWrapper> g_number_format(LINKER_INITIALIZED); |
| +static |
| +LazyInstance<NumberFormatWrapper> g_number_format_int(LINKER_INITIALIZED); |
| + |
| +static |
| +LazyInstance<NumberFormatWrapper> g_number_format_float(LINKER_INITIALIZED); |
| string16 FormatNumber(int64 number) { |
| - icu::NumberFormat* number_format = g_number_format.Get().number_format.get(); |
| + icu::NumberFormat* number_format = |
| + g_number_format_int.Get().number_format.get(); |
|
Evan Stade
2011/06/21 03:18:41
this is the best line of code ever
Avi (use Gerrit)
2011/06/21 14:30:19
You're welcome. I'm here all week.
|
| if (!number_format) { |
| // As a fallback, just return the raw number in a string. |
| @@ -49,4 +54,20 @@ string16 FormatNumber(int64 number) { |
| return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length())); |
| } |
| +string16 FormatDouble(double number, int fractional_digits) { |
| + icu::NumberFormat* number_format = |
| + g_number_format_float.Get().number_format.get(); |
| + |
| + if (!number_format) { |
| + // As a fallback, just return the raw number in a string. |
| + return UTF8ToUTF16(StringPrintf("%f", number)); |
| + } |
| + number_format->setMaximumFractionDigits(fractional_digits); |
| + number_format->setMinimumFractionDigits(fractional_digits); |
| + icu::UnicodeString ustr; |
| + number_format->format(number, ustr); |
| + |
| + return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length())); |
| +} |
| + |
| } // namespace base |