Formatted numeric output: Difference between revisions
Content added Content deleted
(Add min) |
|||
Line 1,224: | Line 1,224: | ||
=={{header|Lambdatalk}}== |
=={{header|Lambdatalk}}== |
||
<lang scheme> |
<lang scheme> |
||
{def |
{def fmt |
||
{lambda {: |
{def padd {lambda {:n :x} {if {< :n 1} then else :x{padd {- :n 1} :x}}}} |
||
{def trunc {lambda {:n} {if {> :n 0} then {floor :n} else {ceil :n}}}} |
|||
{if {= :z 0} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{:trunc {trunc :n}} |
|||
{:dec {abs {trunc {* 1.0e:b {- :n {trunc :n}}}}}} |
|||
⚫ | |||
{if {W.equal? :sign -} |
|||
⚫ | |||
⚫ | |||
{def |
{def numbers |
||
7.125 |
|||
⚫ | |||
10.7 |
|||
⚫ | |||
0.980 |
|||
⚫ | |||
-1000 |
|||
-> format |
|||
559.8 |
|||
-69.99 |
|||
{def numbers 0.000123456789 |
|||
4970.430} |
|||
1.23456789 |
|||
123.456789 |
|||
123456789} |
|||
-> numbers |
-> numbers |
||
{S.map { |
{S.map {fmt 10 3} {numbers}} |
||
-> |
-> |
||
>>>>>>>>> +7.125 |
|||
_0.000123456789 |
|||
>>>>>>>> +10.699 |
|||
____0.123456789 |
|||
>>>>>>>>> +0.980 |
|||
_____1.23456789 |
|||
>>>>>> -1000.000 |
|||
_____123.456789 |
|||
>>>>>>> +559.799 |
|||
______123456789 |
|||
>>>>>>>> -69.989 |
|||
>>>>>> +4970.430 |
|||
</lang> |
</lang> |
||