Commatizing numbers: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) (Added Delphi example) |
(Commatizing numbers en FreeBASIC) |
||
Line 453: | Line 453: | ||
6/9/1946 was a good year for some. |
6/9/1946 was a good year for some. |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
{{trans|VBA}} |
|||
{{trans|Phix}} |
|||
<lang freebasic>Sub commatize(s As String, sep As String = ",", start As Byte = 1, paso As Byte = 3) |
|||
Dim As Integer l = Len(s) |
|||
For i As Integer = start To l |
|||
If Asc(Mid(s, i, 1)) >= Asc("1") And Asc(Mid(s, i, 1)) <= Asc("9") Then |
|||
For j As Integer =i+1 To l+1 |
|||
If j>l Then |
|||
For k As Integer = j-1-paso To i Step -paso |
|||
s = Mid(s, 1, k) + sep + Mid(s, k+1, l-k+1) |
|||
l = Len(s) |
|||
Next k |
|||
Exit For |
|||
Else |
|||
If (Asc(Mid(s, j, 1)) < Asc("0") Or Asc(Mid(s, j, 1)) > Asc("9")) Then |
|||
For k As Integer = j-1-paso To i Step -paso |
|||
s = Mid(s, 1, k) + sep + Mid(s, k+1, l-k+1) |
|||
l = Len(s) |
|||
Next k |
|||
Exit For |
|||
End If |
|||
End If |
|||
Next j |
|||
Exit For |
|||
End If |
|||
Next i |
|||
Print s |
|||
End Sub |
|||
commatize("pi=3.14159265358979323846264338327950288419716939937510582097494459231"," ",6,5) |
|||
commatize("The author has two Z$100000000000000 Zimbabwe notes (100 trillion).",".") |
|||
commatize("\'-in Aus$+1411.8millions\'",",") |
|||
commatize("===US$0017440 millions=== (in 2000 dollars)") |
|||
commatize("123.e8000 is pretty big.") |
|||
commatize("The land area of the earth is 57268900(29% of the surface) square miles.") |
|||
commatize("Ain't no numbers in this here words, nohow, no way, Jose.") |
|||
commatize("James was never known as 0000000007") |
|||
commatize("Arthur Eddington wrote: I believe there are 15747724136275002577605653961181555468044717914527116709366231425076185631031296 protons in the universe.") |
|||
commatize(" $-140000±100 millions.") |
|||
commatize("6/9/1946 was a good year for some.") |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> |
|||
Similar a las entradas de VBA o Phix. |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |