Solved

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

Posted on 2011-03-03
4
335 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

23 Experts available now in Live!

Get 1:1 Help Now