Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Two fields "population" and "F06_popula" (both integers) were used in calculating a new field pct-diff. I asked that the new field be a decimal with a width of 10 and precision of 3. The result has no decimals. See the graphic. But the Layer Properties indicates that pct-diff is a real with 3 decimals. Why are the decimals not visible? enter image description here Thanks -

share|improve this question
    
I can't check right now, but have you tried multiplying the field values by 1.0? Sometimes you need to cast the integers to reals lik that... –  Jose Aug 14 '12 at 22:23
    
Yes that works. It seems that it would be better to not do integer calculations except unless mod() functions are used. The default should be floating point and not dependent on the variable type. –  HealthMaps Aug 15 '12 at 17:23
add comment

2 Answers

I read a discussion http://hub.qgis.org/issues/5153 on the problem which no one seemed to agree on but a solution was found and far from obvious to me.

In the field calculator under conversions in the functions list, use toreal like this: toreal(field1)/field2

it's more like unreal huh?

share|improve this answer
    
toreal( "F06_POPULA" - "POPULATION") / "POPULATION" works. –  HealthMaps Aug 14 '12 at 22:17
    
Thank you! and ("F06_POPULA" - "POPULATION") /toreal( "POPULATION") Got to have a floating point in there somewhere. Also multiplying by 1. will not work, but 1.0 does work. –  HealthMaps Aug 14 '12 at 22:26
add comment
up vote 4 down vote accepted

The formula ("F06-popula"-"population")/"population" is made up of all integer variables. Apparently the field calculator therefore did integer divide. When I multiplied the numerator by 1.0 ( one with a decimal) the result appeared as a floating point number. This was a surprise to me because the statistical languages I use (SAS,R,STATA) always does floating point arithmetic. So do the commercial GIS I use, TransCad.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.