Getting the number of decimal places: Difference between revisions
Getting the number of decimal places (view source)
Revision as of 02:31, 12 February 2022
, 2 years agoGetting the number of decimals en FreeBASIC
(Added solution for Action!) |
(Getting the number of decimals en FreeBASIC) |
||
Line 243:
12.3456 has 14 decimals
1.2345e+54 has 0 decimals</pre>
=={{header|FreeBASIC}}==
<lang freebasic>Function dec(n As Double) As Uinteger
Dim As String c = Str(n)
Return Iif(Instr(c, "."), Len(Mid(c,Instr(c, ".")+1)), 0)
End Function
Dim As Double n(1 To ...) => {7, 12.00, 12.345, 12.345677, 0.142857142857142}
For i As Integer = 1 To Ubound(n)
Print n(i); " has "; dec(n(i)); " decimals"
Next i
Sleep</lang>
{{out}}
<pre> 7 has 0 decimals
12 has 0 decimals
12.345 has 3 decimals
12.345677 has 6 decimals
0.142857142857142 has 15 decimals</pre>
=={{header|Go}}==
|