Getting the number of decimal places: Difference between revisions

Content added Content deleted
(Added solution for Action!)
(Getting the number of decimals en FreeBASIC)
Line 243: Line 243:
12.3456 has 14 decimals
12.3456 has 14 decimals
1.2345e+54 has 0 decimals</pre>
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}}==
=={{header|Go}}==