Solved

Fixing Decimal Points in Visual Basic

Posted on 2003-11-04
11
332 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
Comment Utility
you can use the format function

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

Expert Comment

by:lttia1
Comment Utility
how abt this:

FormattedVariable = Round(YourVariable, 3)
0
 
LVL 1

Expert Comment

by:vkaushik
Comment Utility
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
Comment Utility
1. format function
or
2. convert to string and manuplate
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:LastToKnow0
Comment Utility
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
Comment Utility
Shakhawat: can we have some feedback?
0
 
LVL 1

Expert Comment

by:vkaushik
Comment Utility
Yes mate. We are awaiting the feedback.
0
 

Author Comment

by:Shakhawat
Comment Utility
I already accepted one code and gave the point.

Shakhawat
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now