P PharCyDeD Active Member Licensed User Longtime User Mar 8, 2012 #1 How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4% :sign0163:
How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4% :sign0163:
NJDude Expert Licensed User Longtime User Mar 8, 2012 #2 Take a look at NumberFormat and NumberFormat2. Upvote 0
nfordbscndrd Well-Known Member Licensed User Longtime User Mar 9, 2012 #3 PharCyDeD said: How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4% Click to expand... Round2 (Number As Double, DecimalPlaces As Int) As Double Rounds the given number and leaves up to the specified number of fractional digits. Upvote 0
PharCyDeD said: How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4% Click to expand... Round2 (Number As Double, DecimalPlaces As Int) As Double Rounds the given number and leaves up to the specified number of fractional digits.
M Mahares Expert Licensed User Longtime User Mar 9, 2012 #4 Here is an example: Msgbox(Round2(98.388888767,1) & "%","") yields: 98.4% Upvote 0
P PharCyDeD Active Member Licensed User Longtime User Mar 9, 2012 #5 Thanks! Very helpful guys. Upvote 0
A Azhar Active Member Licensed User Longtime User Jul 25, 2012 #6 Old VB6 Int(nn.nn) and B4A Round functions Hi I can't seem to find a function in core for the old VB6 Int() function. I.e if I have a double say 5.57 the old VB6 Int(5.57) will yield 5 Both B4A Round functions will yield 6 or 6.nn depending on whether you used Round2 with n number of decimal places etc. Is there a similar function to just truncate off all the decimal places and take just the whole number? Thanks Upvote 0
Old VB6 Int(nn.nn) and B4A Round functions Hi I can't seem to find a function in core for the old VB6 Int() function. I.e if I have a double say 5.57 the old VB6 Int(5.57) will yield 5 Both B4A Round functions will yield 6 or 6.nn depending on whether you used Round2 with n number of decimal places etc. Is there a similar function to just truncate off all the decimal places and take just the whole number? Thanks
klaus Expert Licensed User Longtime User Jul 25, 2012 #7 Yes, Floor(x) is equivalent to VB6 Int(x). In Java Int is the keyword for Integer. You have also a Ceil(x) function. With your example Floor(5.57) = 5 Ceil(5.57) = 6 Floor(-5.57) = -6 Ceil(-5.57) = -5 Best regards. Upvote 0
Yes, Floor(x) is equivalent to VB6 Int(x). In Java Int is the keyword for Integer. You have also a Ceil(x) function. With your example Floor(5.57) = 5 Ceil(5.57) = 6 Floor(-5.57) = -6 Ceil(-5.57) = -5 Best regards.
I Inman Well-Known Member Licensed User Longtime User Jul 25, 2012 #8 I believe to get the integer part alone, you simply need to equate the double variable to Int variable Upvote 0
I believe to get the integer part alone, you simply need to equate the double variable to Int variable
A Azhar Active Member Licensed User Longtime User Jul 25, 2012 #9 klaus said: Yes, Floor(x) is equivalent to VB6 Int(x). In Java Int is the keyword for Integer. You have also a Ceil(x) function. With your example Floor(5.57) = 5 Ceil(5.57) = 6 Floor(-5.57) = -6 Ceil(-5.57) = -5 Best regards. Click to expand... Thanks so much! Azhar Upvote 0
klaus said: Yes, Floor(x) is equivalent to VB6 Int(x). In Java Int is the keyword for Integer. You have also a Ceil(x) function. With your example Floor(5.57) = 5 Ceil(5.57) = 6 Floor(-5.57) = -6 Ceil(-5.57) = -5 Best regards. Click to expand... Thanks so much! Azhar
U umsid Member Licensed User Longtime User Nov 8, 2012 #10 I have some Problems with the Floor function: I have this line in my source: CronyResult.Text =Floor(Crony_Factor) the Crony_Factor is: 123.8467365237 the output in the CronyResult Flied is 123.0 I do not know, how to delete the .0 ??? is it a problem of the Floor or of the convert to text or of the output? Thanks for a short reply Guenter Upvote 0
I have some Problems with the Floor function: I have this line in my source: CronyResult.Text =Floor(Crony_Factor) the Crony_Factor is: 123.8467365237 the output in the CronyResult Flied is 123.0 I do not know, how to delete the .0 ??? is it a problem of the Floor or of the convert to text or of the output? Thanks for a short reply Guenter
M MLDev Active Member Licensed User Longtime User Nov 8, 2012 #11 You can remove the .0 with this: Code: CronyResult.Text = Round(Floor(Crony_Factor)) Upvote 0
Justin King New Member Mar 11, 2015 #13 Is it possible to use the Round() function in the designer script? Upvote 0
Roger Daley Well-Known Member Licensed User Longtime User Mar 12, 2015 #14 PharCyDeD Just for clarity, "rounding" has been a debate for some time. Have a look at the thread linked below. The simple answer is, for rounding numbers NumberFormat2 is the correct solution. Erel has been hammering this for sometime even though it took me sometime to catch on he is of course correct. Round2 is not "technically" correct although for most common uses is close enough. For obtaining the integer part only Floor and Ceiling are the way to go. Round2 Vs NumberFormat2 Regards Roger Upvote 0
PharCyDeD Just for clarity, "rounding" has been a debate for some time. Have a look at the thread linked below. The simple answer is, for rounding numbers NumberFormat2 is the correct solution. Erel has been hammering this for sometime even though it took me sometime to catch on he is of course correct. Round2 is not "technically" correct although for most common uses is close enough. For obtaining the integer part only Floor and Ceiling are the way to go. Round2 Vs NumberFormat2 Regards Roger