Solved

Fixing Decimal Points in Visual Basic

Posted on 2003-11-04
11
344 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
11 Comments
 
LVL 3

Accepted Solution

by:
monvelasquez earned 100 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Any Fantasy Football Brute force AI suggestions? 2 58
index Out OF Range Exception error 4 61
What are programming codes and how do they work? 7 94
ASP/VB email question 4 34
This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

772 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