?
Solved

Fixing Decimal Points in Visual Basic

Posted on 2003-11-04
11
Medium Priority
?
376 Views
Last Modified: 2013-12-04
Hi,

I have some calculation in Visual Basic.  Variables are single type. I need to fix the decimal.(After decimal may be 3 digit). How can I round up ? If any body can assist me that would be great.

With thanks

Shakhawat
0
Comment
Question by:Shakhawat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 3

Accepted Solution

by:
monvelasquez earned 400 total points
ID: 9684427
you can use the format function

FormattedVariable = Format(YourVariable, "0.000")
0
 
LVL 2

Expert Comment

by:lttia1
ID: 9684576
how abt this:

FormattedVariable = Round(YourVariable, 3)
0
 
LVL 1

Expert Comment

by:vkaushik
ID: 9684612
You can use the Format function to round up the expression. Following are some examples:

Dim MyStr As String

MyStr = Format(23)   ' Returns "23".

' User-defined numeric formats.
MyStr = Format(5459.4234, "##,##0.000")   ' Returns "5,459.423".
MyStr = Format(334.9723, "###0.000")   ' Returns "334.972".
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 9

Expert Comment

by:bhagyesht
ID: 9685160
1. format function
or
2. convert to string and manuplate
0
 
LVL 1

Expert Comment

by:LastToKnow0
ID: 9690864
You can round to the nearest thousandth (instead of always down) by adding 5/10000 to the number before rounding.

Ex:
Round( 0 + 0.0005, 3) 'returns 0
Round(0.0005 + 0.0005 , 3) 'returns 0.001
Round(0.00049 + 0.0005, 3) 'returns 0

Function RoundNearest(in as Single, precision as Integer) as Single
    RoundNearest=Round(in + .5 * 10 ^(-precision), precision)
End Function
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9699339
Shakhawat: can we have some feedback?
0
 
LVL 1

Expert Comment

by:vkaushik
ID: 9699424
Yes mate. We are awaiting the feedback.
0
 

Author Comment

by:Shakhawat
ID: 10532888
I already accepted one code and gave the point.

Shakhawat
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question