Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Stop Rounding Number


how to stop rounding the number in this equation:

Code:
Dim c As String
Dim a, b As Integer
a = Text34.text
b = Text16.text
c = a + b
Text35.text = Format(c, "#,###.#0")
let say text34 = 10,000.00 and text16 = 10,636.91
in my code the result is 20,637.00 is there a way to stop the rounding. it should be 20,636.91




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Stop Rounding
Good morning,

Having a bit of bother at the moment. I've spent the whole morning making a high scores table for my mini games compilation.

At the end of each mini game, it asks the user for their name, then writes their name and score to a text file in this format "name, score" if the score is higher than whats already in there.

All but 1 of my games always has a score that is a whole number. The exception (in the case a reaction time tester) always rounds to the nearest whole number before saving without me asking it to. As reaction time needs to be very accurate I need it to do no rounding at all.

For example if you got a time of 0.35 it would round it to 0 before writing it to the text file.

If i get a time of 0.75 it will round it to 1 before writing to a text file. This isnt good at all.

I am not experienced programmer at all. So it could be i'm using the wrong type of variables or something. But i dont really know what i should be using.

Im using INTEGER could it be something to do with that? If yes, what should i be using for my variable?

Thanks so much for any help! I look forward to your reply

Mathew

Stop Rounding Up
I have some formulas outputting to a text box. The numbers keep rounding up. How do I stop this?

Stop Rounding Nums
just started write code again after a long time. feel dumb asking simple qusetions. how can i get vb to stop rounding the numbers up.

Num1% = Value
Num2% = FormatNumber(Num1% / 60, 0)

ex.
in this code the if Num1% / 60 = 15.6333 then Num2% is 16, but i need anything < 16 and > 15 to be 15

Stop Rounding My Numbers!!
OK, here's the problem. I have an Integer, let's say it is 250, and I want it to subtract a decimal amount (like, say, 0.342355). However, if I try this, it will store it as 249 instead of whatever 250 minus 0.342355 is. How do I stop this from happening?? Should I use another type for the big integer? What type should I use?

Rounding Number Down?
I was wondering if there was a way to tell vb to allwasy round numbers down no matter what.

So like .8 would round to 0 not 1

Rounding UP A Number
Is there a function that will round UP a number no matter what it is?

i.e. 2.012943 becomes 3

I can't seem to find anything.

Thanks

Rounding A Number
i was wondering how to round a number
i want things like

75,84
not
56.2
5.2342

etc i want it to round to the nearest 1 lol(think thats right)

Number Rounding
Hi

How can I round a value up? I know Round(1.3) will give me 1, but I want to round values like 1.3 to 2.

Thnx for the help

Rounding A Number In Vb 6.0
Hi,
i like to know how to round a number

for example

i want this number 218.5 to be rounded as 219

what is the built in function to be used.
i tried round function but it does not give requried answer
pl. help me

Rounding A Number
I have this line of code

VB Code:
Format((CSng(txtDiscount.Text) / CSng(txtRetail.Text)) * 100, "percent")

and I want to show a percent with 1 decimal place... how could I do this since this shows multiple decimal places. I want it to round up to the .0 of a decimal too..

so if

txtDiscount = 79.99 and
txtRetail = 279.98 then

% should be 28.6%
but right now it comes up as
28.5699%

Rounding A Number
I would like to round off a number to 4 decimal places

13.58386104
What I'm looking for is 13.5839

Thank you

Rounding Of To Whole Number!
Hi,

I want to round of figures from the database to whole numbers.
e.g 90,084.5 to 90085

I tried the Round Function but it does not work properly.
If the figure from the database is e.g 10.5 it gives me 10 instead of 11
or if its 90,084.5 it gives 90,084 instead of 90,085.
below is my code.

Dim Size As Double

If rst.RecordCount <> 0 Then
Size = rst.Fields.item(0)
MsgBox Size

Size = Round(Size, 0)

MsgBox Size, vbInformation + vbOKOnly, "The Role Size is"
end if

Can any body help me please.

Thank you.

Regards,
Feroz

Rounding Number
what function should be used to round up number ? regardless the decimal >
or < .5
e.g. 1.1 round to 2
thanks

Rounding Up A Number
Hi!

How can I round up any number to the next interger or long.

i.e. 30.00001 = 31

Thanks in advance,
Paolo

Rounding A Number Up To Next Integer
I am using VB6 professional and need to round a number up to the next integer. I understand that the Round Function will round down for decimals less than 0.5 and round up for decimals 0.5 or greater. I need to round up to the next integer for all decimal values, no matter how small (or at least to 4 decimal places). I am new to Visual Basic so please bear with me. Any code examples would be very welcome.

Thanks,

Steve.

Newbie Needs Help Rounding A Number
Hi all

I am writing a program to calculate table sizes for SQL Servers. I have all the equation stuff right, but I need to be able to round a number as such:

1.1 = 1
1.9 = 1
2.6 = 2
2.2 = 2

Do you see, if it is a decimal number it must always round down so if my variable equals 2 point anything it must equal 2. Hope somebody can help I'm just new at this but I really am liking it.

Thanks, Justin

I Need A Number Rounding Fuction
Hi

Has anyone got a function to email to me that rounds a floating point number to a certain number of decimal places.

The built in VB Round() function has bugs.

I read somewhere on this site that is you round 3.45 to 1 decimal place, it will make it 3.4 rather than 3.5

This is quite urgent, so please help.

Thanks!

How To Display Just A Whole Number Without Rounding
First of all, thank you very much for reading this. I have been looking around and y'all are very helpful! Thanks so much!

It's been awhile since I have done anything coding and I am stuck. And I have to admit that I am embarrassed...

Here is an example of what I have...

Dim intTotal as Integer
Dim sngDollar as Single
intTotal = txtTotal.text
sngDollar = intTotal / 100
lblTotal.Caption = sngDollar

The question is... How do I get the lblTotal.Caption to drop the remainders and only display the whole number WITHOUT rounding? I hope that I am asking this correctly...

Again, thank you very much for reading this and I appreciate any comments or suggestions that you have! Have a great day!

Rounding To Next Highest Whole Number
Does anyone know of a function or a method that I can use to round a number up to the next highest whole number? If I have, for example, 3.2, I want it to round to 4 and if I have 3.8 I want it to round to 4. I've looked around and asked around and can't find any ways of doing this.

Rounding Down A TypeDouble Number
if say i had a dbl number of 10.3 or 10.7, how can i round either down to 10 - basically making it an integer?

**RESOLVED** Rounding To The Nearest Whole Number
Hi

I need help! I have conducted a search on this forum and have
found nothing.... what I need help with is rounding to the nearest
whole number ???

i.e
1.5 becomes 2.0
1.4 becomes 1.0

etc etc

Your help and time is very much appreciated

Rounding Down An Unknown Number According To Its (negative) Size
Hi there,

a week ago I started a thread called "Rounding up an unknown number according to its size".

I wanted to find a reasonable map category upper bound for model results. For example, result 204.2 would have an upper bound of 250; 2.042 would lead to 2.5; 2,634 would lead to 3,000, etc.

The code below does a great job as long as n > 1.

n = Fix(x) + (5 * 10 ^ (Len("" & Fix(x)) - 2)) - Fix(x) Mod (5 * 10 ^ (Len("" & Fix(x)) - 2))
' where x is Single positive number, n is a Long number. Any x < 1 will give n = 1.

Now I realize that I also need a lower bound for negative numbers. For example, model result "- 127.8" should return "-150".

Would you have any idea how I can achieve this?

Thanks for your help!

Rounding Up An Unknown Number Depending On Its Size
Hi there,

I would like to map values across a landscape through 5 map categories. For example, map class 1 with values 0-<10, class 2 with values 10-<20, etc.

Trouble is, the max. value of any of these variables can be very different.

I need the max. value to determine the upper bound of the max map class.

For example, max. value may be 8,375.4 or 0.875.

The code below rounds up, but doesn't do this depending on the size of sngMaxValue.

sngUpperBound_MaxClass = Fix(sngMaxValue) + 1

Ideally, 8,375.4 would become 8,500 or 9,000.

Ideally, 0.875 would become 0.9 or even 1.00.

Ideally, 124.9 would become 125 or 150.

How can I round up an unknown number in dependence of its actual size in a generic way?

Thank you for your help.

Trim Number Without Rounding [RESOLVED - Thanks Guys]
I'm looking for the easiest way to trim a number ... say 2.4392345, back to 2.43.

My usual way to do this whould be to use the format function, but it rounds it up. Is there a function for doing this?

Thanks

CInt Rounds The Number, But I Need To Display Without Rounding
When I use CInt(Text1) + CInt(Text2) in a formula, it rounds the answer..i need my answer without rounding......
Thank You

Rounding Error: Wrong Number Of Arguments Or Invalid Property Assignment
I am experimenting with a program that calculates compound interest. As you can see the balance is produced in a box for each year for 9 years. Now I want to have a button by each of those boxes so I can round the balance. Now when I click on the button to round I get an error saying "Wrong number of arguments or invalid property assignment." I have tried everthing I can think of to fix this but can't. Hoping one of you can check out some of my source and figure out whats wrong. Here are parts of the source that I think might be helpful:

f = Val(Interest.Text): P = Val(Principal.Text): z = 100: Dim B As Single
------------------
I = f / z
A = I * P
B = A + P
--------------------
Year1.Text = CStr(B)
--------------------
Private Sub Round_Click()
B = Round(B, 2)
End Sub
--------------------
Thanks

How Do I Stop A Number From Having The E+ On It?
how do i stop a number from having the E+# on it, like this 1.12345E+6 ..????

Stop Generating Same Number Twice
What would be the best way to stop generating the same number twice?

This is the code im using to generate the numbers

Code:

Randomize
RndQues = Int((30 * Rnd) + 1)

Rounding Numbers To 2 Decimal Places - How To ? (Rounding)
I am returning math to a variable (and/or a text box) BUT I only want to have two or three decimal places, that are rounded off.

I cant figure out how to round them. I've tried setting text box properties, calling 'as currency' but I dont know what else to do.

Thank you.

Stop Error? Or I Will Stop You!
Oh the title i just wanted to get your attention. it looks like it worked though.

So now to the real problem, How do you make an easy error handler for a for next loop that sets or reads the properties of controls. and it tries to read a "timer.width".

I don't want ot know a way to avoid the error just a way to handle it.

Regards
E.P.

Rounding
Does anyone know why this is happening? When my colleague e mails me a spreadsheet it rounds differently to my sheet, even though I am viewing them both on my pc in my excel (we're both on excel 2000)


thanks

Rounding Off
Hi All

I am having a small problem and was wondering if someone could please help me.

When i enter a number into a cell, for example 7.8, it rounds it of to 8.0. How can i stop this from happening as i need 7.8 to be displayed.

I've been to Format/Cells/Number and have got it to display 1 decimal place, but i don't want it to be rounded off

Many Thanks in advance

Rounding
I am having a small problem with my rounding, and I do not want to use the currency format function becasuse I do not want a $ in the text box.

I want to take a number in a text box and round it so that it reflects currency, no problem right? Using:
Text1.Text = Round(Text1.Text, 2)

That works fine if the number is 1.152, it will round it like this 1.15 but if the number is 1.7 I want it to become 1.70 so it looks like currency.

Rounding Down
how would i round a number down no matter what?

Rounding ....
Hello,

This is my first time posting here. I am pretty new to visual basic.

I am trying to round a dollar amount to either the whole dollar or the half of dollar.

If anyone could help me with this, I would appreciate it.

Thanks for your help )

Rounding Up
Let's say that PST is $0.345, I am finding with the format expression that I am getting a value of $0.34 not the rounded up version normal for any extra decimal of 5 or over.
PST = Format(PST, "0.00")

Any help on how this can be corrected this

Thanks
Robert

Rounding...
I need to Always Round down the number to whole i.e 25.4792397392 = 25 and 498.9378 = 498
does this do it
i want ot drop the decimal

Rounding...
How would i go about rounding something like

53.4893

to just

53.48

?

Rounding Down
Is there a function expression or a keyword to allow me to round down to the nearest whole number? Instead of me coding a seperate function.

Help With Rounding....
i don't know whats wrong, when i run thin in Query Analizer i get '3'. how can i make SQL to stop rounding....



Code:
SELECT ROUND(22/7, 2)

Rounding Up
Hey guys,
I am having problems with a model i am currently making as it keeps displaying decimal points. I tried writing something which disabled the textbox from using the decimal point but of course it just carries the number to the other side of the decimal point makiing a huge number. Does anyone know any code to round up a figure?
Thanks

Rounding
how do you round to 3 or 4 decimal points?

i can round but i want 3 or 4 decimal places


divide 31 into 5 to see what i mean

.1612903 is the answer

i want it to show .1613

Rounding Off
can some1 pls explain how i can make a quick sub that will round off numbers. e.g. if i have 3 text boxes, how do i divide the numbers in the first 2 textboxes, and give a rounded of answer in the 3rd?

Rounding To 0.95
I have a rounding problem en don't know how to solve it.
I want to round a number to the nearest .95 value

42,98 should be 42,95
43,05 should be 42,95
43,80 should be 43.95

Can someone point me to the right direction?
thanks in advance
Rony

Rounding Down
Hey... is there a function that will round down? Here's my situation.

I have an variable nIndex which is an Integer. I have another called CurrentRow which is also an integer (this program uses excel, but this isn't an excel related question, so I'm keeping it here.

Now then, when CurrentRow is between 1-20, nIndex should = 0, for 21-40, it should equal 1, and so on.

The code I've used to do this is:

nIndex = CurrentRow / 20

However, when CurrentRow = 13, nIndex = 1. So it's rounding the 0.65 up to 1. Is there any way to get it to round down?

Rounding
I generate a number that I need to round to the nearest multiple of 32. At the moment, I use the following, which rounds it down: -


Code:

' rNo is the random number

x = rNo - (rNo mod 32)
Is this the best way? (I'm guessing not). Isn't there a way to round it to the nearest 32, and not just round down?
Thanks!

Rounding
why is VB rounding uneven fractions to the nearest whole numbers? I'd like exact decimals...anyone know what's up?

Rounding Down
ok i know it is possible to round a number using the round() function. however i have a program that requires that the number be ONLY rounded down, otherwise the output is very errorous. i tried Cstr() then filtering the integer but thats not how i want to do it. i dont mind if i have to code more that converting to string then working it out through IFs and such, but i do want it to be more mathmatical. can anyone help me with this? i did notice i SQL (i think it was SQL but im not sure now-it was one of the languages in the professional MSDN) called Floor() but cant find a equivilent.

Rounding To 0.05
I am creating a program which needs to show the total cost of items and calculate the amount of change payable.

However, I live in Australia where the smallest amount of money is the 5 cent coin. Therefore there is no point displaying the amount of money owed as $20.73 etc.

Is there any way to easily round these numbers up/down to the nearest 0.05.

eg:
20.73 becomes 20.75
30.11 becomes 30.10
etc

Any help would be much appreciated

Copyright 2005-08 www.BigResource.com, All rights reserved