S sparks9941 Member Licensed User Longtime User Nov 15, 2014 #1 How can I display a calculated number in a label as a percentage? Example: .243687 in my label, i want it to read 24.37% labelpercent.text = ((label1.text - label2.text ) / label1.text) i want labelpercent.text to be XX.XX% in visual basic i used: labelpercent = Format((label1 - label2) / label1, "percent") that worked great in vb, i am very new to basic4android, still on trial version Last edited: Nov 15, 2014
How can I display a calculated number in a label as a percentage? Example: .243687 in my label, i want it to read 24.37% labelpercent.text = ((label1.text - label2.text ) / label1.text) i want labelpercent.text to be XX.XX% in visual basic i used: labelpercent = Format((label1 - label2) / label1, "percent") that worked great in vb, i am very new to basic4android, still on trial version
JTmartins Active Member Licensed User Longtime User Nov 15, 2014 #2 Someting like Code: labelpercent.Text= "12"& " %" of course instead of the "12" you should place your variable with the value you need. Upvote 0
Someting like Code: labelpercent.Text= "12"& " %" of course instead of the "12" you should place your variable with the value you need.
S sparks9941 Member Licensed User Longtime User Nov 15, 2014 #3 thanks, but that just added a % sign, i need to convert the decimal to percent with 2 places on each side of decimal like .2499987 to 25.00% Upvote 0
thanks, but that just added a % sign, i need to convert the decimal to percent with 2 places on each side of decimal like .2499987 to 25.00%
C cyiwin Active Member Licensed User Longtime User Nov 15, 2014 #4 you can convert ugly doubles to a more readable string. Code: MyString = NumberFormat2(MyDouble,2,2,2,False) Upvote 0
you can convert ugly doubles to a more readable string. Code: MyString = NumberFormat2(MyDouble,2,2,2,False)
klaus Expert Licensed User Longtime User Nov 15, 2014 #5 Code: labelpercent.Text = NumberFormat2(((label1 - label2) / label1 * 100), 1, 2 ,2 , False) & "%" Last edited: Nov 16, 2014 Upvote 0
S sparks9941 Member Licensed User Longtime User Nov 15, 2014 #6 Klaus, that worked pretty good but it comes up with 0.25% and i need it to convert the fraction to % like 25.00% Upvote 0
Klaus, that worked pretty good but it comes up with 0.25% and i need it to convert the fraction to % like 25.00%
S sparks9941 Member Licensed User Longtime User Nov 15, 2014 #7 this is what worked well for me in visual basic lblpercent = Format ((lblratio1 - lblratio2) / lblratio1, "percent") this gave me the actual percent of drop from ratio1 to ratio2 , like 25.89% so far all i am getting my label to display is 0.25% when i need it to display 25.89% (example) Upvote 0
this is what worked well for me in visual basic lblpercent = Format ((lblratio1 - lblratio2) / lblratio1, "percent") this gave me the actual percent of drop from ratio1 to ratio2 , like 25.89% so far all i am getting my label to display is 0.25% when i need it to display 25.89% (example)
M Mahares Expert Licensed User Longtime User Nov 15, 2014 #8 I have a feeling you want something like this example: Code: Label1.text= 23.8 :Label2.text=18 labelpercent.Text = NumberFormat2(((Label1.text - Label2.text) / Label1.text *100), 1, 2 ,2 , False) & "%" 'Displays: 24.37% Upvote 0
I have a feeling you want something like this example: Code: Label1.text= 23.8 :Label2.text=18 labelpercent.Text = NumberFormat2(((Label1.text - Label2.text) / Label1.text *100), 1, 2 ,2 , False) & "%" 'Displays: 24.37%
S sparks9941 Member Licensed User Longtime User Nov 16, 2014 #9 Thank you Mahares, as soon as i seen your post i new it would work, and it does. I should have figured that out but I am learning. Upvote 0
Thank you Mahares, as soon as i seen your post i new it would work, and it does. I should have figured that out but I am learning.
wonder Expert Licensed User Longtime User Nov 16, 2014 #10 Code: labelpercent.text = Round2((((label1.text - label2.text ) / label1.text) * 100), 2) & "%" Upvote 0
derez Expert Licensed User Longtime User Nov 16, 2014 #11 Round2( ... Click to expand... No, read this thread http://www.b4x.com/android/forum/threads/rounding-numbers-round2-or-numberformat2.46768/ Upvote 0
Round2( ... Click to expand... No, read this thread http://www.b4x.com/android/forum/threads/rounding-numbers-round2-or-numberformat2.46768/
wonder Expert Licensed User Longtime User Nov 16, 2014 #12 Thank you for pointing me to that thread, @derez. To my understanding, NumberFormat2 will be more accurate than Round2 for precise calculations. Is there any issue however, while using Round2 when the result doesn't have to be that precise? Most of us are taught that for digits below 5, round down, for 5 and greater round up. Click to expand... When rounding just one digit, we look at a digital range of 5 cases each - 0,1,2,3,4 and 5,6,7,8,9 Click to expand... I also was taught this way and I guess that it's what everyone uses on it's daily life. Upvote 0
Thank you for pointing me to that thread, @derez. To my understanding, NumberFormat2 will be more accurate than Round2 for precise calculations. Is there any issue however, while using Round2 when the result doesn't have to be that precise? Most of us are taught that for digits below 5, round down, for 5 and greater round up. Click to expand... When rounding just one digit, we look at a digital range of 5 cases each - 0,1,2,3,4 and 5,6,7,8,9 Click to expand... I also was taught this way and I guess that it's what everyone uses on it's daily life.
derez Expert Licensed User Longtime User Nov 16, 2014 #13 I also was taught this way and I guess that it's what everyone uses on it's daily life. Click to expand... Yes but checking the mean showed that numberformat is doing the job better. Upvote 0
I also was taught this way and I guess that it's what everyone uses on it's daily life. Click to expand... Yes but checking the mean showed that numberformat is doing the job better.
wonder Expert Licensed User Longtime User Nov 16, 2014 #14 Let imagine you're building a Forex Trading app, where a price variation of 1/100th of a cent (depending on the invested value) will result in profits/losses of thousands of dollars. Would you perform calculations using NumberFormat2 in this app, without hesitation? Last edited: Nov 16, 2014 Upvote 0
Let imagine you're building a Forex Trading app, where a price variation of 1/100th of a cent (depending on the invested value) will result in profits/losses of thousands of dollars. Would you perform calculations using NumberFormat2 in this app, without hesitation?
klaus Expert Licensed User Longtime User Nov 16, 2014 #15 I'm afraid that you are confusing things. You should use Round if you want to round a numeric value, Round returns a Double ! You should use NumberFormat to display numbers with the given format, NumberFormat returns a String. This has nothing to with calculations ! Upvote 0
I'm afraid that you are confusing things. You should use Round if you want to round a numeric value, Round returns a Double ! You should use NumberFormat to display numbers with the given format, NumberFormat returns a String. This has nothing to with calculations !
derez Expert Licensed User Longtime User Nov 16, 2014 #16 Would you perform calculations using NumberFormat2 in this app, without hesitation? Click to expand... You can make the application cheat by more... just know the difference between the two options. Upvote 0
Would you perform calculations using NumberFormat2 in this app, without hesitation? Click to expand... You can make the application cheat by more... just know the difference between the two options.