[Jython-checkins] jython: Implement 'n' formatting type for integers (#1718) using Java's localized
nicholas.riley
jython-checkins at python.org
Wed Mar 21 21:34:58 CET 2012
http://hg.python.org/jython/rev/6eca8f634134
changeset: 6461:6eca8f634134
user: Nicholas Riley <njriley at illinois.edu>
date: Wed Mar 21 16:27:56 2012 -0400
summary:
Implement 'n' formatting type for integers (#1718) using Java's localized number formatting.
Also some PEP 378 changes I forgot to commit earlier.
files:
src/org/python/core/PyInteger.java | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/org/python/core/PyInteger.java b/src/org/python/core/PyInteger.java
--- a/src/org/python/core/PyInteger.java
+++ b/src/org/python/core/PyInteger.java
@@ -992,8 +992,13 @@
radix = 2;
}
- // TODO locale-specific formatting for 'n'
- if (value instanceof BigInteger) {
+ if (spec.type == 'n') {
+ strValue = NumberFormat.getNumberInstance().format(value);
+ } else if (spec.thousands_separators) {
+ NumberFormat format = NumberFormat.getNumberInstance(Locale.US);
+ format.setGroupingUsed(true);
+ strValue = format.format(value);
+ } else if (value instanceof BigInteger) {
strValue = ((BigInteger) value).toString(radix);
} else {
strValue = Integer.toString((Integer) value, radix);
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list