Getting the number of decimal places: Difference between revisions
Content added Content deleted
(Haskell added) |
|||
Line 214: | Line 214: | ||
1.2345e+54 has 0 decimals |
1.2345e+54 has 0 decimals |
||
</pre> |
</pre> |
||
=={{Header|Haskell}}== |
|||
<lang Haskell>decimal :: String -> Int |
|||
decimal [] = 0 |
|||
decimal ('.':xs) = length xs |
|||
decimal (_:xs) = decimal xs |
|||
numDecimal :: Double -> Int |
|||
numDecimal = decimal . show |
|||
main = print . map numDecimal $ [12.0, 12.345, 12.3450, 12.345555555555, 12.34555555555555555555, 1.2345e+54]</lang> |
|||
{{out}} |
|||
<pre>[1,3,3,12,15,7]</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
<lang java>public static int findNumOfDec(double x){ |
<lang java>public static int findNumOfDec(double x){ |