By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Prevent Auto Rounding

P: n/a
Hello,
Let's say Textbox1.text = 10
size = 46

answer = (Val(TextBox1.Text) * 100.5) / size
TextBox2.Text = Format(answer, "#######.000")

The answer is: 21.847830...
However, when I get the result in textbox2.text - it shows:
21.848

While I understand that this is rounding up - how can I
make it so that I still get the 3 decimal places - but it
shows:
21.847
(without the rounding)
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Keith,

Microsoft has used the International Banking standard. When you ask in this
newsgroup who is using that than there comes no answer. You have to do
rounding with your own routines.

See here the questions and answer in the language.vb which has been about
rounding.

http://tinyurl.com/353eu

I hope this helps?

Cor
Hello,
Let's say Textbox1.text = 10
size = 46

answer = (Val(TextBox1.Text) * 100.5) / size
TextBox2.Text = Format(answer, "#######.000")

The answer is: 21.847830...
However, when I get the result in textbox2.text - it shows:
21.848

While I understand that this is rounding up - how can I
make it so that I still get the 3 decimal places - but it
shows:
21.847
(without the rounding)

Nov 20 '05 #2

P: n/a
Keith,

You have 2 options, use the INSTR and LEFT functions OR multiply the value
up, convert it using the INT function then divide it back down. See
examples below;

Option 1:
Dim Answer as String
Dim Ptr As Integer
Answer = CStr( (10 * 100.5) / 46) 'Calculate your value and
convert to a string
Ptr = Instr(Answer, ".") 'Check if the result
has a DECIMAL
If (Ptr = 0) Then 'If there is NOT a
decimal
TextBox2.Text = Answer 'Display the answer
as-is
Else 'Otherwise
TextBox2.Text = Left(Answer, Instr + 3) 'Display the string up
to the Decimal + next 3 characters
End If

Option 2:
Dim Answer As Double

Answer = (10 * 100.5) / 46
Answer = Answer * 1000
Answer = Int(Answer)
Answer = Answer / 1000
TextBox2.Text = Answer.ToString

NOTE: In Option 2 you could perform all the math on 1 line as in;
TextBox2.Text = (Int(((10 * 100.5) / 46) * 1000) / 1000).ToString
"Keith" <an*******@discussions.microsoft.com> wrote in message
news:1f*****************************@phx.gbl...
Hello,
Let's say Textbox1.text = 10
size = 46

answer = (Val(TextBox1.Text) * 100.5) / size
TextBox2.Text = Format(answer, "#######.000")

The answer is: 21.847830...
However, when I get the result in textbox2.text - it shows:
21.848

While I understand that this is rounding up - how can I
make it so that I still get the 3 decimal places - but it
shows:
21.847
(without the rounding)

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.