Getting the number of decimal places: Difference between revisions
→{{header|C}}: Changed to be in accordance with task description.
(add RPL) |
(→{{header|C}}: Changed to be in accordance with task description.) |
||
Line 167:
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
int findNumOfDec(
sprintf(buffer, "%.14f", x);▼
▲ return num;
}
void test(
int num = findNumOfDec(
printf("%s has %d decimal%s\n", s, num, p);
}
int main() {
test("12
test("12.
test("12.
test("12.
test("12.
test(
char str[64];
test(str);
return 0;
}</syntaxhighlight>
{{out}}
<pre>
<pre>12.000000 has 0 decimals▼
12
12.
12.
12.
1234500000000000060751116919315055127939946206157864960.000000 has 0 decimals</pre>▼
12.34555555555555555555 has 20 decimals
</pre>
=={{header|C++}}==
|