on master help sign in
Fix integer fields in YAML metadata

If a numeric field contains an integer number, it should be shown as an integer number. Without this patch, the field: answer = 42 would be shown as "42.0". Before the introduction of YAML in metadata, this was treated as a string and therefore shown as just "42". This patch reinstates the older (and IMHO correct) behavior.

commit6fbffc586cd951180c5a4ed328bd43a1f3920a85 authorNikolaos S. Papaspyrou <nickie@softlab.ntua.gr> dateMon 31 Oct 2016, 10:36 (10 years ago) parentab34240
1 file changed+3−1
src/Data/Yaml/Extended.hs+3−1
src/Data/Yaml/Extended.hs+3−1
@@ -7,12 +7,14 @@ module Data.Yaml.Extended
77import qualified Data.Text as T
88import qualified Data.Vector as V
99import Data.Yaml
10+import Data.Scientific
1011
1112toString :: Value -> Maybe String
1213toString (String t) = Just (T.unpack t)
1314toString (Bool True) = Just "true"
1415toString (Bool False) = Just "false"
15−toString (Number d) = Just (show d)
16+toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d)
17+ | otherwise = Just (show d)
1618toString _ = Nothing
1719
1820toList :: Value -> Maybe [Value]