UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Bmi, Access 2016    
 
   
mike60smart
post Jun 20 2019, 01:39 AM
Post#1


UtterAccess VIP
Posts: 13,225
Joined: 6-June 05
From: Dunbar,Scotland


Hi Everyone

I am trying to calculate BMI with the following calculation:-

BMI:[Weight]/([Height]*[Height])

My values are Weight = 3.5 kgs and Height = 49 cms

This should produce a BMI of 14.5

The calculation in the query is producing this:- 1.45772594752187E-03

The fields in the table are formatted as Double

Any help appreciated

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
Phil_cattivocara...
post Jun 20 2019, 01:55 AM
Post#2



Posts: 303
Joined: 2-April 18



BMI is a calculated field in the query. You have to define the number format for that calculated field in query structure.

Be careful to trouble in calculation with flaoating point datatype.

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
mike60smart
post Jun 20 2019, 02:13 AM
Post#3


UtterAccess VIP
Posts: 13,225
Joined: 6-June 05
From: Dunbar,Scotland


Hi Phil

I have tried all options for formatting the field in the query with no success


--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
Phil_cattivocara...
post Jun 20 2019, 02:33 AM
Post#4



Posts: 303
Joined: 2-April 18



In query design, right click on the calculated field, Properties, Format: choose Standard, Decimal position: the number of digits you want to display after the decimal point.
Remember: this is only how you see the number, not ther real value. If you show 6 decimal digits this does not mean the value has 6 decimal digits, the real value can have ...
If you want to handle that value with 5 decimal digits only you have to apply a rounding and I would suggest you to consider Decimal DataType.
Be careful (again, yes) with flaoting point datatype and "errors" with calculation.

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
PhilS
post Jun 20 2019, 03:55 AM
Post#5



Posts: 580
Joined: 26-May 15
From: The middle of Germany


QUOTE
I am trying to calculate BMI with the following calculation:-

BMI:[Weight]/([Height]*[Height])

My values are Weight = 3.5 kgs and Height = 49 cms

If you store height in cm your formula is wrong.
BMI is weight in kilograms divided by height in meters squared.
CODE
BMI:[Weight]/(([Height]/100)*([Height]/100))


--------------------
Go to the top of the page
 
Phil_cattivocara...
post Jun 20 2019, 04:13 AM
Post#6



Posts: 303
Joined: 2-April 18



QUOTE (PhilS)
If you store height in cm your formula is wrong

I know you did not write that "for me" but I only want to underline I do not even know what BMI is, I only answerd about the "format number"

OT: Are you "Mr CodeCabinet"? I never notices your name is Phillip: more than a name, a guarantee. End OT

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
mike60smart
post Jun 20 2019, 07:07 AM
Post#7


UtterAccess VIP
Posts: 13,225
Joined: 6-June 05
From: Dunbar,Scotland


Hi Phil

Your formulae produces the following result:- 145772.594752187

I managed to get the correct BMI using this :- BMI: [weight]*703/[Height]^2/703 = 14.58

No, I am not Mr Code Cabinet

Many thanks for looking

cheers.gif

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
Phil_cattivocara...
post Jun 20 2019, 07:11 AM
Post#8



Posts: 303
Joined: 2-April 18



QUOTE (mike60smart)
No, I am not Mr Code Cabinet

Yes, I know you are not "Mr CodeCabinet". I wrote it for PhilS.
If it is solved... ok.

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
cheekybuddha
post Jun 20 2019, 07:46 AM
Post#9


UtterAccess VIP
Posts: 11,419
Joined: 6-December 03
From: Telegraph Hill


Hi Mike,

Your new formula is using the constant to convert weight in pounds and height in inches, but essentially since you have the constant in both the numerator and the denominator it cancels itself out.

Your original formula failed because of the order of precedence of arithmetic operators. Division is performed before multiplication, so effectively you were doing:
CODE
(Weight / Height) * Height

instead of:
CODE
Weight / (Height * Height)


Phil is correct - you must convert centimetres to metres.

I think your formula ought to be:
CODE
BMI: [weight]/(([height]/100)*([height]/100))

Or:
CODE
BMI: [weight]/(([height]/100)^2)


Using your weight and height of 3.5kgs and 49cm, the result is:
CODE
?3.5/((49/100)^2)
14.5772594752187


hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
mike60smart
post Jun 20 2019, 07:54 AM
Post#10


UtterAccess VIP
Posts: 13,225
Joined: 6-June 05
From: Dunbar,Scotland


Hi David

OK now. By changing value input from 0.49 to 49 it now works just great

Many thanks yet again

cheers.gif

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
cheekybuddha
post Jun 20 2019, 08:02 AM
Post#11


UtterAccess VIP
Posts: 11,419
Joined: 6-December 03
From: Telegraph Hill


If your height is stored in metres (0.49) then remove the division by 100 which is used to convert centimetres to metres.
CODE
BMI: [weight]/([height]^2)


In your original post you said the height was 49cms, so we all assumed you were storing the height in centimetres. blush.gif

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
mike60smart
post Jun 20 2019, 08:11 AM
Post#12


UtterAccess VIP
Posts: 13,225
Joined: 6-June 05
From: Dunbar,Scotland


Hi David

Maths was never my strong point.


--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
cheekybuddha
post Jun 20 2019, 08:13 AM
Post#13


UtterAccess VIP
Posts: 11,419
Joined: 6-December 03
From: Telegraph Hill


It's all numbers to me! wink.gif

thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
GroverParkGeorge
post Jun 20 2019, 08:14 AM
Post#14


UA Admin
Posts: 35,307
Joined: 20-June 02
From: Newcastle, WA


If I'm not mistaken PhilS is the person behind codekabinett.com

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th July 2019 - 11:27 PM