Solved

VB.Net Format string into currency (56.4543534) to (56.45)

Posted on 2011-03-03
4
339 Views
Last Modified: 2012-08-14
Hey,

How would I go about changing a string into this format:
56.45

I have tried String.Format("{0:C}", Cost), but it still comes out with more than two after decimal numbers.

I have a lot of strings that contain numbers, so converting each to a double would be a lengthy process. Any easy ways?

Thanks!
Jessee
0
Comment
Question by:Letsgetcoding
  • 3
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 35025677
vb.net:
Dim num As String = "12.454353"
Dim s As String = Format(Double.Parse(num), "#.##")

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 35025695
either this, or using string manipulation:
        Dim num As String = "12.454353"
        Dim s As String = num.Substring(0, num.IndexOf(".") + 3)
s --> "12.45"
0
 

Author Comment

by:Letsgetcoding
ID: 35026256
Is it possible to do it without creating another string? For example
Dim num As String = "12.454353"
num = Format(Double.Parse(num), "#.##")
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 35026294
@Letsgetcoding
yes.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

11 Experts available now in Live!

Get 1:1 Help Now