When declaring floating-point variable, I don't understand the amount of precision needed for the stored object in RPG ??
In my exercice, I enter the number of copies for example the value 5
.
The total amount is 0.50 euros but I have like message:
I don't understand how to declare the variable total
correctly in double.
H
D NumberCopy S 3S 0
D Total S ???
*
/Free
dsply 'Enter your copy number please : ' '' NumberCopy;
If (NumberCopy < 11);
Total = NumberCopy * 0.10;
ElseIf (NumberCopy < 31);
Total = (10 * 0.10) + (NumberCopy - 10) * 0.09;
Else;
Total = (10 * 0.10) + (20 * 0.09) + (NumberCopy - 30) * 0.08;
EndIf;
dsply ('The amount is of ' + %Char(Total) + ' euros');
*inlr = *on;
/End-Free
Here I find this on RPGPDM.
D Float1 S 8F
https://www.rpgpgm.com/2014/02/defining-variables-in-rpg-all-free.html
to say it at the beginning of your exercise DONT USE FLOAT IN RPG. It will make you pretty unhappy. To answer your question: dcl-s total float(8);
You have two problems with float:
If you wanna display a float you can do something like that
dcl-s outputString char(10) inz;
dcl-s total float(8) inz (5);
outputString = %char(%dec(total: 10: 2));
dsply outputString;
Some hints: