ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Both period and comma usable for decimal seperator, normal ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Both period and comma usable for decimal seperator, normal ?

    Hello,

    Our system value for decimal separator is the comma. In our RPGLE programs, we use DECEDIT('0,'). However, we can code both using commas and periods.

    Code:
    SumComma = 50 + 0,01;
    SumPeriod = 50 + 0.01;
    Both give 50.01 (in debug, it uses periods to show decimals even though the job has comma as the decimal separator. Why that is, is another question.).

    Code:
    SumComma = 50 + 1,01;
    SumPeriod = 50 + 1.01;
    Both give 51.01.

    I tried doing

    Code:
    SumPeriod = 50 + 1.000,01;
    just to see but got compile errors.

    We only need/want the comma to be used as the decimal separator. How is it we can also use the period?

  • #2
    How often do you hardcode numbers in your source code?
    Normally numeric values are located in tables/physical files or passed as parameters or entered in a display file (where the decimal comma may be used in your case!)
    In RPG you can use both (that is a feature not a bug)

    Comment


    • #3
      We sometimes need to add a certain tolerance when doing calculations (so + or - a certain value to a sum, for example). We hardcode the value in the program because I don't think it happens often enough to justify creating a table just to store tolerance values.

      Ok, so it's normal that I can use both. I was just confused because our system value is comma so I didn't expect periods to work or was afraid it would be considered the digit separator.

      Thanks for the answer.

      Comment


      • Scholli2000
        Scholli2000 commented
        Editing a comment
        Isn’t this one of the major issues we encounter when facing our hard-to-handle legacy applications: Someone / everyone in the past said: "I don’t think it happens often enough to justify creating a table". :-)

    • #4
      fwiw... you can't ever type thousands separators into numeric literals in RPG. (or any other language that I can think of.)

      Both commas and periods work in RPG, which is helpful because it makes the code easier for people who work in different environments. For example, suppose I wrote a program here in the USA where we use the period as our separator, and published it in a magazine, or made it open source, or posted it to a forum like this... then you (or someone else in Europe) downloaded the code and wanted to use it. Think of how much trouble it'd be to change it! (unless it happened to be a trivial example)

      So I think it's awesome that either comma or period works... makes life better.

      Comment


      • #5
        Good to know.

        In my code, I only use the period as a separator, although in everyday life we use a comma here.
        I guess if I’d seen something like "if field1 = field2*2,1" in an RPG program I would have tried looking up the meaning of the comma operator.

        Oh, in fixed format it looks even more confusing (real life example of an old program I just found on our machine)
        Code:
         C    FLD           ADD       3,5           FLD
        To me the code suggests FLD is an array and you add 3 to the first and 5 to the second element--or 3 to the fifth.

        Comment

        Working...
        X