bydamien Posted March 28, 2009 Report Posted March 28, 2009 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 for read.. 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 :( i dont understand where is my wrong point please help me.. thank you
Pete Dowson Posted March 28, 2009 Report Posted March 28, 2009 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now