xquery/XQuery__DecimalFormatter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 02 Jul 2018 08:46:01 +0200
changeset 305 bad21c4f64bf
parent 296 ea3dbc023c80
permissions -rw-r--r--
Tagged Smalltalk/X 8.0.0

"{ Package: 'stx:goodies/xmlsuite/xquery' }"

"{ NameSpace: XQuery }"

XQueryNumberFormatter subclass:#DecimalFormatter
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'XQuery-Types'
!


!DecimalFormatter methodsFor:'number formatting'!

nonStandardCanonicalLexicalForm
    TypeError raiseErrorString: 'Non standart numbers (INF, NaN) not allowed for decimal'.

    "Created: / 16-11-2009 / 18:19:20 / Jan Kurs <kursj1@fel.cvut.cz>"
    "Modified: / 17-11-2009 / 17:39:45 / Jan Kurs <kursj1@fel.cvut.cz>"
!

standardCanonicalLexicalForm
      | format |

      (number = 0) ifTrue:
      [
        ^ '0'.
      ].

      format := '%.', self fractionDigits asString, 'f'.
      ^ number printStringFormat: format.

"/    | aMantissa anExponent |
"/    aMantissa := self mantissa.
"/    anExponent := self exponent.
"/
"/    (anExponent > 0) ifTrue:
"/    [
"/        (anExponent >= 6) ifTrue:
"/        [
"/            ^ aMantissa printString, 'E', anExponent printString.
"/        ] 
"/        ifFalse:
"/        [
"/            | fractionDigits |
"/            fractionDigits := self fractionDigits.
"/            ^ self number printStringFormat: '%.', fractionDigits storeString, 'f'
"/        ].
"/    ]
"/    ifFalse:
"/    [
"/        (anExponent < -6) ifTrue:
"/        [
"/            ^ aMantissa printString, 'E', anExponent printString.
"/        ]
"/        ifFalse:
"/        [
"/            | format |
"/            format := '%.', self fractionDigits asString, 'f'.
"/            ^ number printStringFormat: format.
"/        ].
"/    ]

    "Created: / 16-11-2009 / 18:19:11 / Jan Kurs <kursj1@fel.cvut.cz>"
    "Modified: / 17-11-2009 / 17:45:52 / Jan Kurs <kursj1@fel.cvut.cz>"
! !

!DecimalFormatter class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !