Solved

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

Posted on 2011-03-03
4
344 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
[X]
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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 86
Get month and date in a format 4 45
Asp.Net Session Question 2 36
Telerik RadEditor Control Save 8 15
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

733 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