Commatizing numbers: Difference between revisions
Content added Content deleted
m (made a large dot (multiplication gyph) symbol larger to make it easier to read, added verbiage about pi being expressed in base ten.) |
|||
Line 362: | Line 362: | ||
Before: 6/9/1946 was a good year for some. |
Before: 6/9/1946 was a good year for some. |
||
After: 6/9/1946 was a good year for some.</pre> |
After: 6/9/1946 was a good year for some.</pre> |
||
=={{header|Phix}}== |
|||
(Ignoring the bulk of the task requirement.) |
|||
Of course you can and should insert commas when creating the string in the first place, rather than struggling with it later. |
|||
<lang Phix>printf(1,"Without commas: %8.2f; with: %,8.2f\n",14440.00)</lang> |
|||
{{Out}} |
|||
<pre> |
|||
Without commas: 14440.00; with: 14,440.00 |
|||
</pre> |
|||
If however you have identified a fragment of text, then you can do things like this: |
|||
<lang Phix>function add_commas(string s) |
|||
for i=length(s)-3 to 1 by -3 do |
|||
s[i+1..i] = "," |
|||
end for |
|||
return s |
|||
end function |
|||
string s = "---123456789---" |
|||
s[4..-4] = add_commas(s[4..-4]) -- (or ..+12 if you prefer) |
|||
?s</lang> |
|||
<pre> |
|||
"---123,456,789---" |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |