formatn: Formatting of doubles.

[ bsd3, library, text ] [ Propose Tags ] [ Report a vulnerability ]

This package provides support for number formatting styles, especially styles involving significant figure calculations.

Usage

>>> import Data.FormatN
>>> comma (Just 3) 1234
1,230

[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1, 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.0, 0.3.0.1, 0.3.1.0
Change log ChangeLog.md
Dependencies base (>=4.14 && <5), containers (>=0.6 && <0.8), text (>=1.2 && <2.2) [details]
Tested with ghc ==9.10.1, ghc ==9.6.5, ghc ==9.8.2
License BSD-3-Clause
Copyright Tony Day (c) 2016
Author Tony Day
Maintainer tonyday567@gmail.com
Category text
Home page https://github.com/tonyday567/formatn#readme
Bug tracker https://github.com/tonyday567/formatn/issues
Source repo head: git clone https://github.com/tonyday567/formatn
Uploaded by tonyday567 at 2024-10-12T22:00:40Z
Distributions LTSHaskell:0.3.1.0, NixOS:0.3.0.1, Stackage:0.3.1.0
Reverse Dependencies 3 direct, 5 indirect [details]
Downloads 1009 total (59 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-10-20 [all 1 reports]

Readme for formatn-0.3.1.0

[back to package description]

formatn

img img

A library for support of:

  • significant figure rounding of numbers, and
  • common number formatting patterns.

Usage

:reload
:set prompt "> "

:set -Wno-type-defaults
:set -XOverloadedStrings
import Data.FormatN

xs = [(-1),0,0.1,1,1.01,1.02,1.1,1.2]

fixed (Just 2) <$> xs
decimal (Just 2) <$> xs
formats False False (const DecimalStyle) (Just 2) xs
formats False True (const DecimalStyle) (Just 2) xs
distinguish 4 False True (const DecimalStyle) (Just 2) xs

Ok, 14 modules loaded.
> >
>
> ["-1.00","0.00","0.10","1.00","1.01","1.02","1.10","1.20"]
["-1.0","0.0","0.10","1.0","1.0","1.0","1.1","1.2"]
["-1.00","0.00","0.10","1.00","1.00","1.00","1.10","1.20"]
["-1.0","0.0","0.1","1.0","1.0","1.0","1.1","1.2"]
["-1.00","0.00","0.10","1.00","1.01","1.02","1.10","1.20"]

getting 0 right

fixed

fixed (Just 3) <$> [0, 0.5, 1.5, 2.0]

["0.000","0.500","1.500","2.000"]

fixed defaults to representing Doubles in the same manner as Haskell does ie with a trailing ’.0’

fixed Nothing <$> [0, 0.5, 1.5, 2]

["0.0","0.5","1.5","2.0"]

expt

expt Nothing 0

0e0

expt (Just 2) 1
expt (Just 2) 0

1.0e0
0.0e0

decimal

decimal Nothing 0
decimal (Just 1) 0
decimal (Just 3) 0

0
0
0.00

percent

percent is a little weird any way you cut it.

percent decimalSF (Just 4) 0
percent decimalSF (Just 4) 1

0.0%
100.0%

inclusion in lists

formats True False commaPrecStyle Nothing [0, 0.5, 1.5, 2]
formats True False commaPrecStyle (Just 1) [0, 1, 10]
formats True False commaPrecStyle (Just 1) [0, 0.5, 1.5, 2]
formats True False commaPrecStyle (Just 2) [0, 0.5, 1.5, 2]
formats True True commaPrecStyle (Just 6) [0, 0.5, 1.5, 2]

["0.0","0.5","1.5","2.0"]
[" 0"," 1","10"]
["0.0","0.5","2.0","2.0"]
["0.00","0.50","1.50","2.00"]
["0.0","0.5","1.5","2.0"]