The simFlight Network Forums

## Recommended Posts

Dear Pete and all

i have a problem i want to share maybe somebody will sign me true way, i want to load fuel on my program and im following this

capCenter = ((Int32)getCCenter.Value); for capacty reading

LevCenter = ((double)getLevCenter.Value * 100 / (128 * 65536)); for level reading

GalCenter = capCenter * LevCenter / 100; for gallon result

gallonresult * 2.72 = kg result

i thing this read mentallity is correct is here have any problem please tell me.. so now i know this is my kg result if i want to set fuel that tank im using this..

before i must to convert kg to gallon

400 kg / 2.72 = 147 gallon after i must to convert this result to fs language im using this function.

capcenter capacity is 2130 gallon

public double FuelConvert(double dGalon, Int32 iCap)

{

double iBur = dGalon / 100 * (128 * 65536);

double ioff = iBur * 100 / (128 * 65536) / iCap * 100;

return Math.Round(ioff / 100 * (128 * 65536));

}

so after this function i have one result is this 578932 and im writting this result on getLevCenter.Value after when i turn to plane and check on fuel 440 kg :(

thank you

##### Share on other sites

Compare these two:

LevCenter = ((double)getLevCenter.Value * 100 / (128 * 65536)); for level reading

...

double iBur = dGalon / 100 * (128 * 65536);

Don't you see something seriously different which would explain your result?

gallonresult * 2.72 = kg result

Rather than assume a fixed gallon <> kg relationship you should really use the fuel weight value provided at offset 0AF4. Capacity varies with air pressure. You should use the 0AF4 value then convert pounds to kg.

double ioff = iBur * 100 / (128 * 65536) / iCap * 100;

I think you should use more paretheses here. What is being divided by and multiplied by what? I've been a programmer for 46 years and I couldn't swear what the compiler would do with that.

return Math.Round(ioff / 100 * (128 * 65536));

That looks wrong too.

I think you just need to be more careful with your placing of * and / operators, and do use parentheses ( ) to make things clear and explicit.

Regards

Pete

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.