Skip to content

Commit

Permalink
Don't use scientific notation in input fields with float / double values
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Sep 29, 2021
1 parent 6c1ae29 commit 6545122
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import qualified IHP.Log as Log
import Data.Dynamic
import Data.Scientific
import GHC.Stack
import qualified Numeric

-- | Provides the db connection and some IHP-specific db configuration
data ModelContext = ModelContext
Expand Down Expand Up @@ -110,10 +111,10 @@ instance InputValue Integer where
inputValue = tshow

instance InputValue Double where
inputValue = tshow
inputValue double = cs (Numeric.showFFloat Nothing double "")

instance InputValue Float where
inputValue = tshow
inputValue float = cs (Numeric.showFFloat Nothing float "")

instance InputValue Bool where
inputValue True = "on"
Expand Down
8 changes: 8 additions & 0 deletions Test/ModelSupportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ tests = do
describe "Double" do
it "should return numeric representation" do
(inputValue (1.337 :: Double)) `shouldBe` "1.337"

it "should deal with large numbers" do
-- https://stackoverflow.com/questions/69306646/ihp-haskell-field-display-format-double-values
(inputValue (50000000 :: Double)) `shouldBe` "50000000.0"

describe "Scientific" do
it "should return numeric representation" do
Expand All @@ -40,6 +44,10 @@ tests = do
describe "Float" do
it "should return numeric representation" do
(inputValue (1.337 :: Float)) `shouldBe` "1.337"

it "should deal with large numbers" do
-- https://stackoverflow.com/questions/69306646/ihp-haskell-field-display-format-double-values
(inputValue (50000000 :: Float)) `shouldBe` "50000000.0"

describe "Bool" do
it "should deal with True and False" do
Expand Down

0 comments on commit 6545122

Please sign in to comment.