RosettaCodeData/Task/Formatted-numeric-output/PL-I/formatted-numeric-output-2.pli

26 lines
704 B
Plaintext

lz: Proc Options(main);
/*********************************************************************
* 10.09.2013 Walter Pachl one way to treat negative numbers
* another would be using a Picture of 'S(9)9.V(3)9' or '-(9)9.V(3)9'
*********************************************************************/
Call z2lz(1.2);
Call z2lz(-1.32);
Call z2lz(123456789.012);
Call z2lz(-23456789.012);
Call z2lz(-123456789.012);
z2lz: Proc(z);
Dcl z Dec Fixed(15,3); ;
Dcl s Char(13) Based(addr(p));
Dcl p Pic'(9)9.V(3)9';
p=z;
If z<0 Then
If left(s,1)='0' Then substr(s,1,1)='-';
Else Do;
Put Skip List(z,'can''t be formatted that way');
Return;
End;
Put Skip List(z,s);
End;
End;