Getting the number of decimal places: Difference between revisions

Content added Content deleted
m (→‎{{header|Lambdatalk}}: minor change)
Line 422: Line 422:
=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
In lambdatalk numbers are words/strings, some operators, like "+,-,*,/,...", know what to do with words like "123".
In lambdatalk numbers are words/strings, some operators, like "+,-,*,/,...", know what to do with words like "123".

A first answer could be

<lang Scheme>
<lang Scheme>
{W.length
{W.length
Line 428: Line 431:
-> 4
-> 4
</lang>
</lang>

This is a better one, if considering that ending zeroes should not be considered as decimals

<lang Schema>
{def decimals
{def decimals.r
{lambda {:w}
{if {= {W.first :w} 0}
then {decimals.r {W.rest :w}}
else :w}}}
{lambda {:w}
{W.length
{decimals.r
{S.first
{W.reverse
{S.replace \. by space in :w}}}}}}}
-> decimals

{decimals 12.34560001230000}
-> 10
</lang>
Numbers can be of any size.


=={{header|Perl}}==
=={{header|Perl}}==