1

Why is totals showing zero for me in this snippet?

Integer stats;

Decimal total;

Integer cntOrg=60;

stats=200;
total = stats/cntOrg;

system.debug('Values for '+org+' is ' + total);
1

1 Answer 1

3

Your stats and cntOrg should be in decimal then only output will be expected

Decimal stats;

Decimal total;

Decimal cntOrg=60;

stats=200;
total = stats/cntOrg;

system.debug('Values for '+org+' is ' + total);

If you divide integer datatype no. then result be in integer type.

So in your case 3 will be return not decimal numbers

If you divide Decimal datatype no.hen result be in Decimal type.

So in your case 3.33333333333333333333333333333333 will be return with decimal numbers

2
  • I just don't understand why? I am dividing an integer by another integer, only the result should be a decimal type, no?
    – Apex N-u-b
    Commented Mar 20, 2016 at 14:35
  • @ApexN-u-b no if you divide 2 Integer type variable it will return only Integer number you will not get complete value. If you divide two Decimal no then it will return complete value .
    – Ratan Paul
    Commented Mar 20, 2016 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .