Skip to content

Integer>>asWords needed  #63

@dalehenrich

Description

@dalehenrich

for now, ZnExampleStorageRestServerDelegateTest>>testQuery is an expected failure until Integer>>asWords added to GsDevKit.

Here's the Pharo implementation:

asWords
    "SmallInteger maxVal asWords"
    | mils minus three num answer milCount |
    self = 0 ifTrue: [^'zero'].
    mils := #('' ' thousand' ' million' ' billion' ' trillion' ' quadrillion' ' quintillion' ' sextillion' ' septillion' ' octillion' ' nonillion' ' decillion' ' undecillion' ' duodecillion' ' tredecillion' ' quattuordecillion' ' quindecillion' ' sexdecillion' ' septendecillion' ' octodecillion' ' novemdecillion' ' vigintillion').
    num := self.
    minus := ''.
    self < 0 ifTrue: [
        minus := 'negative '.
        num := num negated.
    ].
    answer := String new.
    milCount := 1.
    [num > 0] whileTrue: [
        three := (num \\ 1000) threeDigitName.
        num := num // 1000.
        three isEmpty ifFalse: [
            answer isEmpty ifFalse: [
                answer := ', ',answer
            ].
            answer := three,(mils at: milCount),answer.
        ].
        milCount := milCount + 1.
    ].
    ^minus,answer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions