Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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