i18n: Do not represent zero as "-0".
authorLudovic Courtès <ludo@gnu.org>
Sun, 12 Feb 2017 21:59:17 +0000 (22:59 +0100)
committerAndy Wingo <wingo@pobox.com>
Wed, 1 Mar 2017 20:04:42 +0000 (21:04 +0100)
Partly fixes <http://bugs.gnu.org/24990>.
Reported by Martin Michel <dev@famic.de>.

* module/ice-9/i18n.scm (monetary-amount->locale-string): Don't negate
AMOUNT when it's zero.
(number->locale-string): Likewise.
* test-suite/tests/i18n.test ("number->locale-string")["positive inexact
zero, 1 digit"]: New test.
("monetary-amount->locale-string")["positive inexact zero"]: New test.

module/ice-9/i18n.scm
test-suite/tests/i18n.test

index 1d12dd061e21201d45e87c882d891ccd18ae0da9..1326a2a02d1fe8c6489440024b569224978e0844 100644 (file)
@@ -1,6 +1,7 @@
 ;;;; i18n.scm --- internationalization support    -*- coding: utf-8 -*-
 
-;;;;   Copyright (C) 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
+;;;;   Copyright (C) 2006, 2007, 2009, 2010, 2012,
+;;;;      2017 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -335,7 +336,7 @@ locale is used."
                                    (substring dec 0 fraction-digits)
                                    dec)))))
 
-         (external-repr (number->string (if (> amount 0) amount (- amount))))
+         (external-repr (number->string (if (>= amount 0) amount (- amount))))
          (int+dec   (string-split external-repr #\.))
          (int       (car int+dec))
          (dec       (decimal-part (if (null? (cdr int+dec))
@@ -387,7 +388,7 @@ number of fractional digits to be displayed."
                                    (substring dec 0 fraction-digits)
                                    dec))))))
 
-    (let* ((external-repr (number->string (if (> number 0)
+    (let* ((external-repr (number->string (if (>= number 0)
                                               number
                                               (- number))))
            (int+dec   (string-split external-repr #\.))
index 0078baa1790a3b0c00dafeb733d825ee70bbf545..53ed93232740634ac2e6ecc7e7226e08aca39cb9 100644 (file)
@@ -1,7 +1,7 @@
 ;;;; i18n.test --- Exercise the i18n API.  -*- coding: utf-8; mode: scheme; -*-
 ;;;;
 ;;;; Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012,
-;;;;   2013, 2014, 2015, 2016 Free Software Foundation, Inc.
+;;;;   2013, 2014, 2015, 2016, 2017 Free Software Foundation, Inc.
 ;;;; Ludovic Courtès
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
       (string=? "1234.567" (number->locale-string 1234.567)))
 
     (pass-if "fraction, 1 digit"
-      (string=? "1234.5" (number->locale-string 1234.567 1))))
+      (string=? "1234.5" (number->locale-string 1234.567 1)))
+
+    (pass-if "positive inexact zero, 1 digit"
+      (string=? "0.0" (number->locale-string .0 1))))
 
   (with-test-prefix "French"
 
        (lambda ()
          (let ((fr (make-locale LC_ALL %french-locale-name)))
            (string=? "1 234,56 EUR "
-                     (monetary-amount->locale-string 1234.567 #t fr))))))))
+                     (monetary-amount->locale-string 1234.567 #t
+                                                     fr))))))
+
+    (pass-if "positive inexact zero"
+      (under-french-locale-or-unresolved
+       (lambda ()
+         (let ((fr (make-locale LC_ALL %french-locale-name)))
+           (string=? "0,0 +EUR"
+                     (monetary-amount->locale-string 0. #f fr))))))))