I have 2 questions about floating and packed data formats in natural :
1. Here We generally use packed(P) and numeric(N) formats to define numeric digits with decimal point that is floating point. But when natural has Floating point format(F), why cannot we use F format?
2. In my program i define a field with P10. Then inside the program i will move value of length 7 bytes to field. So internally what will be the result i mean to say how many bytes it will store? Is it N/2 +1 ?
Where i can get all this information in software ag website?
You have to think about the purpose. Here’s a rule of thumb: You should use floats for scientific and for some statistical calculations. But for pure business calculations (like calculating VAT or so) you should use Numeric/Packed Fields.
Format N is a “display” format, so when using N-fields in computations, Natural will always convert it to a P internally, do the computation, convert it back to N.
So floating can be used only for scientific calculations. and N is only for display format. so if i define a variable = N7, internally P will be 7/2 +1 = 3.5 +1 = 5 bytes. Please correct if i am wrong?
No, I didn’t say (or imply) that, you can use N in computations, otherwise Natural would disallow it, you should just be aware of the implications.
If you use a field in arithmetic operations a lot, and only output it once, using P makes sense because it saves Natural the overhead of converting from N to P to N every time.
As for your other question, a format “N” field will always occupy the number of bytes equal to the number of digits specified. So a N7.2 field will occupy 9 bytes.
Your formula for packed fields is wrong, it isn’t (n/2) + 1 but (n + 1) / 2.
So a P7 field occupies (7+1)/2 = 4 bytes, not 5.