Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-number into LemonIceScream-master
  • Loading branch information
cuducos committed Sep 13, 2019
2 parents b336995 + 30369cf commit 614d164
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/FormatNumber.elm
Expand Up @@ -38,31 +38,31 @@ import Stringfy exposing (stringfy)
import FormatNumber.Locales exposing (Locale, frenchLocale, spanishLocale, usLocale)
format { decimals = 2, thousandSeparator = ".", decimalSeparator = ",", negativePrefix = "−", negativeSuffix = "", positivePrefix = "", positiveSuffix = "" } 123456.789
format { decimals = 2, thousandSeparator = ".", decimalSeparator = ",", negativePrefix = "−", negativeSuffix = "", positivePrefix = "", positiveSuffix = "", zeroPrefix = "", zeroSuffix = "" } 123456.789
--> "123.456,79"
format { decimals = 2, thousandSeparator = ",", decimalSeparator = ".", negativePrefix = "−", negativeSuffix = "", positivePrefix = "", positiveSuffix = "" } 1234.5567
format { decimals = 2, thousandSeparator = ",", decimalSeparator = ".", negativePrefix = "−", negativeSuffix = "", positivePrefix = "", positiveSuffix = "", zeroPrefix = "", zeroSuffix = "" } 1234.5567
--> "1,234.56"
format (Locale 3 "." "," "−" "" "" "") -7654.3210
format (Locale 3 "." "," "−" "" "" "" "" "") -7654.3210
--> "−7.654,321"
format (Locale 1 "," "." "−" "" "" "") -0.01
format (Locale 1 "," "." "−" "" "" "" "" "") -0.01
--> "0.0"
format (Locale 2 "," "." "−" "" "" "") 0.01
format (Locale 2 "," "." "−" "" "" "" "" "") 0.01
--> "0.01"
format (Locale 0 "," "." "−" "" "" "") 123.456
format (Locale 0 "," "." "−" "" "" "" "" "") 123.456
--> "123"
format (Locale 0 "," "." "−" "" "" "") 1e9
format (Locale 0 "," "." "−" "" "" "" "" "") 1e9
--> "1,000,000,000"
format (Locale 5 "," "." "−" "" "" "") 1.0
format (Locale 5 "," "." "−" "" "" "" "" "") 1.0
--> "1.00000"
format (Locale 2 "," "." "(" ")" "" "") -1.0
format (Locale 2 "," "." "(" ")" "" "" "" "") -1.0
--> "(1.00)"
format usLocale pi
Expand Down
8 changes: 5 additions & 3 deletions src/FormatNumber/Locales.elm
Expand Up @@ -27,6 +27,8 @@ type alias Locale =
, negativeSuffix : String
, positivePrefix : String
, positiveSuffix : String
, zeroPrefix : String
, zeroSuffix : String
}


Expand All @@ -37,7 +39,7 @@ numbers, but no sufix or prefix for positive numbers.
-}
frenchLocale : Locale
frenchLocale =
Locale 3 "\u{202F}" "," "" "" "" ""
Locale 3 "\u{202F}" "," "" "" "" "" "" ""


{-| Locale used in Spain, Italy and Norway. It has 3 decimals digits, uses a
Expand All @@ -47,7 +49,7 @@ positive numbers.
-}
spanishLocale : Locale
spanishLocale =
Locale 3 "." "," "" "" "" ""
Locale 3 "." "," "" "" "" "" "" ""


{-| Locale used in the United States, Great Britain and Thailand. It has 2
Expand All @@ -57,4 +59,4 @@ numbers, no sufix or prefix for positive numbers.
-}
usLocale : Locale
usLocale =
Locale 2 "," "." "" "" "" ""
Locale 2 "," "." "" "" "" "" "" ""
29 changes: 28 additions & 1 deletion src/Parser.elm
Expand Up @@ -126,6 +126,30 @@ splitThousands integers =
--> , suffix = "+"
--> }
parse { usLocale | negativePrefix = "(", negativeSuffix = ")", positiveSuffix = " ", zeroSuffix = " " } -12.34
--> { original = -12.34
--> , integers = ["12"]
--> , decimals = "34"
--> , prefix = "("
--> , suffix = ")"
--> }
parse { usLocale | negativePrefix = "(", negativeSuffix = ")", positiveSuffix = " ", zeroSuffix = " " } 12.34
--> { original = 12.34
--> , integers = ["12"]
--> , decimals = "34"
--> , prefix = ""
--> , suffix = " "
--> }
parse { usLocale | negativePrefix = "(", negativeSuffix = ")", positiveSuffix = " ", zeroSuffix = " " } 0.0
--> { original = 0.0
--> , integers = ["0"]
--> , decimals = "00"
--> , prefix = ""
--> , suffix = " "
--> }
parse { usLocale | decimals = 0 } 1234567.89
--> { original = 1234567.89
--> , integers = ["1", "234", "568"]
Expand Down Expand Up @@ -241,4 +265,7 @@ parse locale original =
}

Zero ->
partial
{ partial
| prefix = locale.zeroPrefix
, suffix = locale.zeroSuffix
}
32 changes: 16 additions & 16 deletions src/Stringfy.elm
Expand Up @@ -11,52 +11,52 @@ import Parser exposing (FormattedNumber)
import FormatNumber.Locales exposing (Locale)
import Parser exposing (FormattedNumber)
stringfy (Locale 3 "." "," "−" "" "" "") Nothing (FormattedNumber 3.1415 ["3"] "142" "" "")
stringfy (Locale 3 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 3.1415 ["3"] "142" "" "")
--> "3,142"
stringfy (Locale 3 "." "," "−" "" "" "") Nothing (FormattedNumber -3.1415 ["3"] "142" "−" "")
stringfy (Locale 3 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber -3.1415 ["3"] "142" "−" "")
--> "−3,142"
stringfy (Locale 0 "." "," "−" "" "" "") Nothing (FormattedNumber 1234567.89 ["1", "234", "568"] "" "" "")
stringfy (Locale 0 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 1234567.89 ["1", "234", "568"] "" "" "")
--> "1.234.568"
stringfy (Locale 0 "." "," "−" "" "" "") Nothing (FormattedNumber 1234567.89 ["1", "234", "568"] "" "−" "")
stringfy (Locale 0 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 1234567.89 ["1", "234", "568"] "" "−" "")
--> "−1.234.568"
stringfy (Locale 1 "." "," "−" "" "+" "") Nothing (FormattedNumber 999.9 ["999"] "9" "+" "")
stringfy (Locale 1 "." "," "−" "" "+" "" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "+" "")
--> "+999,9"
stringfy (Locale 1 "." "," "−" "" "" "+") Nothing (FormattedNumber 999.9 ["999"] "9" "" "+")
stringfy (Locale 1 "." "," "−" "" "" "+" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "" "+")
--> "999,9+"
stringfy (Locale 1 "." "," "−" "" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "−" "")
stringfy (Locale 1 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "−" "")
--> "−999,9"
stringfy (Locale 1 "." "," "−" "" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "−" "")
stringfy (Locale 1 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 999.9 ["999"] "9" "−" "")
--> "−999,9"
stringfy (Locale 2 "." "," "−" "" "" "") Nothing (FormattedNumber 0.001 ["0"] "00" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 0.001 ["0"] "00" "" "")
--> "0,00"
stringfy (Locale 2 "." "," "−" "" "" "") Nothing (FormattedNumber 0.001 ["0"] "00" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 0.001 ["0"] "00" "" "")
--> "0,00"
stringfy (Locale 1 "." "," "−" "" "" "") Nothing (FormattedNumber 5497558138.88 ["5", "497", "558", "138"] "9" "" "")
stringfy (Locale 1 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 5497558138.88 ["5", "497", "558", "138"] "9" "" "")
--> "5.497.558.138,9"
stringfy (Locale 1 "." "," "−" "" "" "") Nothing (FormattedNumber 5497558138.88 ["5", "497", "558", "138"] "9" "−" "")
stringfy (Locale 1 "." "," "−" "" "" "" "" "") Nothing (FormattedNumber 5497558138.88 ["5", "497", "558", "138"] "9" "−" "")
--> "−5.497.558.138,9"
stringfy (Locale 2 "." "," "−" "" "" "") (Just KeepZeros) (FormattedNumber 10.0 ["10"] "00" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") (Just KeepZeros) (FormattedNumber 10.0 ["10"] "00" "" "")
--> "10"
stringfy (Locale 2 "." "," "−" "" "" "") (Just KeepZeros) (FormattedNumber 10.1 ["10"] "10" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") (Just KeepZeros) (FormattedNumber 10.1 ["10"] "10" "" "")
--> "10,10"
stringfy (Locale 2 "." "," "−" "" "" "") (Just RemoveZeros) (FormattedNumber 10.0 ["10"] "00" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") (Just RemoveZeros) (FormattedNumber 10.0 ["10"] "00" "" "")
--> "10"
stringfy (Locale 2 "." "," "−" "" "" "") (Just RemoveZeros) (FormattedNumber 10.1 ["10"] "10" "" "")
stringfy (Locale 2 "." "," "−" "" "" "" "" "") (Just RemoveZeros) (FormattedNumber 10.1 ["10"] "10" "" "")
--> "10,1"
-}
Expand Down

0 comments on commit 614d164

Please sign in to comment.