Solved

Fixing Decimal Points in Visual Basic

Posted on 2003-11-04
11
340 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
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9685160
1. format function
or
2. convert to string and manuplate
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 68
tidtcpserver connection lost handle 2 72
recursion example 16 112
What are programming codes and how do they work? 7 75
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now