473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Prevent Auto Rounding

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
2 2291
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
1
by: keliie | last post by:
Hello, I've created a form that contains a single unbound combo box and two subforms. The two subforms display the results of a query (driven by the combo box selection) in both tabular and...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
11
by: vinceboy | last post by:
Hi..guys!I have a drop down menu with javascript null validation.However,instead of clicking submit button,it will immediately auto redirect after option was selected.Is it possible to prevent this...
4
by: since | last post by:
How do I in IE prevent the onclick action from being fired when I am done dragging? have tried "window.event.cancelBubble = true", for onmouseup , onmousedown, and onmousemove handlers. The onclick...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.