Source language: Translate to:

Centimeters to feet

General questions about NeoBook

Moderator: Neosoft Support

Centimeters to feet

Postby stu » Wed Jun 24, 2015 7:01 am

Hi...

I'm having some trouble converting a centimeter value into a feet/inch format...

For example 170cm using a formula would retrieve something like: 5ft 6.929134in
I would like to get: 5ft 7in (5.7)

(?)
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Centimeters to feet

Postby dpayer » Wed Jun 24, 2015 8:45 am

stu wrote:Hi...

I'm having some trouble converting a centimeter value into a feet/inch format...

For example 170cm using a formula would retrieve something like: 5ft 6.929134in
I would like to get: 5ft 7in (5.7)

(?)


This turned out to be a bit more difficult than I thought it would be! Decimal system--> non decimal with decimal remainder

Create a new 640x480 pub and then copy the code below to it. You will see my logic in the button action.

I edited this after understanding how the MATH / TRUNC commands work.

[
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=8
Name=Text1
X=40
Y=41
W=564
H=40
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs36\cf0 Convert CM to Foot/Inch}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=2
ObjectType=9
Name=cminput
X=50
Y=117
W=147
H=27
Anchor=0
VarName=[cminput]
Align=1
EditLen=0
LineColor=0
LineWidth=2
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=8
Name=Text2
X=79
Y=151
W=83
H=27
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Centimeter}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=4
ObjectType=3
Name=PushButton1
X=215
Y=112
W=162
H=38
Anchor=0
Text=Convert
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=If "[combobox1]" "=" ""¶    Alertbox "Input required" "Select Decimal Accuracy Value"¶    GoToLine "endofscript"¶Endif¶¶Math "([cminput]*393701)/1000000" "[ComboBox1]" "[totalinch]"¶.going to 10 decimals to get accuracy¶Math "[totalinch]/12" "10" "[totalfeet]"¶Math "trunc([totalfeet])" "-1" "[feet]"¶Math "([totalfeet]-[feet])*12" "10" "[remaininginch]"¶Math "([remaininginch]/1)" "[combobox1]" "[inch]"¶¶¶:endofscript
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=8
Name=Text3
X=411
Y=112
W=58
H=35
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs36\cf0 [feet]}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=6
ObjectType=8
Name=Text4
X=413
Y=154
W=55
H=27
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Feet}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=7
ObjectType=8
Name=Text5
X=525
Y=112
W=108
H=35
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs36\cf0 [inch]}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=8
ObjectType=8
Name=Text6
X=521
Y=154
W=55
H=27
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Inches}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=9
ObjectType=11
Name=ComboBox1
X=528
Y=202
W=51
H=24
Anchor=0
Text=0¶1¶2¶3¶4¶
VarName=[ComboBox1]
VarType=0
XPTheme=Yes
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=10
ObjectType=8
Name=Text7
X=492
Y=232
W=130
H=27
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Decimal Accuracy}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=11
Last edited by dpayer on Wed Jun 24, 2015 9:41 am, edited 6 times in total.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Centimeters to feet

Postby Gaev » Wed Jun 24, 2015 8:48 am

Stu:

Are you looking (in your example) for a returned value of ...

5 ft. 7 in. (correct rounded value)

or

5.7 ( :? )

... each one requires a different solution.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Centimeters to feet

Postby Gaev » Wed Jun 24, 2015 9:12 am

stu:

For correct value (e.g. 5 ft. and 7 in.) ...
Code: Select all
Math "[myCentimeters]/2.54]" "0" "[wholeInches]"

Math "trunc([wholeInches]/12)" "0" "[myFeet]"

Math "[wholeInches]-([myFeet]*12)" "0" "[myInches]"

SetVar "[myResult]" "[myFeet] ft. and [myInches] in."


Setup ...

- a TextEntry box with associated variable [myCentimeters]

- and a Text box with this content ...

myCentimeters = [myCentimeters]
wholeInches = [wholeInches]
myFeet = [myFeet]
myInches = [myInches]
myResult = [myResult]

... to test it.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Centimeters to feet

Postby stu » Wed Jun 24, 2015 10:32 am

Thanks for your replies...

So a bit of the background... I want store users/persons on a database table and Height is one of the fields, then comes the problem of having people saying "I'm 5.7" and other saying "I'm 1.70"... I decided the way to go is to store in centimeters and then giving the oportunity of displaying the result in CM or INCH according to what the user wants... hence the problem of bringing the 170 back to the frontend and show it as INCH.

But thanks for the input!

I absolutely skip this:

A mathematical formula. The formula can include the following operators and functions: +, -, *, /, ^, Abs, Sin, Cos, Atan, Sqr, Sqrt, Round, Trunc. Parentheses and variables may also be used in formulas.


With this I can get the value rounded so i can display it back again...

:D
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 1 guest