• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Vb.Net to C# conversion (cont.) - Microsoft.VisualBasic

What is the C# equivilent to

Microsoft.VisualBasic.Strings.FormatCurrency()
Microsoft.VisualBasic.TriState.UseDefault

I have this line of code that is no longer working:
--------------------------------------------------------------------------------------------------------
using Microsoft.VisualBasic;
...
Session["TotalCost"] = Strings.FormatCurrency(calculatedTotalValue, 2, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault);
--------------------------------------------------------------------------------------------------------

Nugs
0
Nugs
Asked:
Nugs
  • 6
  • 4
  • 2
  • +1
4 Solutions
 
Bob LearnedCommented:
You shoulda looked at the result for ToString("c"):

Session["TotalCost"] = calculatedTotalValue.ToString("c");

Bob
0
 
drichardsCommented:
In your original, you probably have not added a reference to Microsoft.VisualBasic.  The code should compile and run as written assuming calculatedTotalValue has some kind of number in it.

I bring this up just to point out that simply adding a 'using' is not enough if the correct assembly reference does not exist.
0
 
NugsAuthor Commented:
I basically need to convert calculatedTotalValue to a currency format with 2 decimal places.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
drichardsCommented:
either ToString("c") or your original code will give you that.
0
 
NugsAuthor Commented:
Original code does not work in C#...
0
 
NugsAuthor Commented:
What about: Session["TotalCost"] = String.Format("{0:c}", calculatedTotalValue);
0
 
existenz2Commented:
Session["TotalCost"] = calculatedTotalValue.ToString("#.##");

that should work. Have a look at: http://john-sheehan.com/blog/wp-content/uploads/msnet-formatting-strings.pdf 
0
 
drichardsCommented:
That too.  It's just a longhand version of calculatedTotalValue.ToString("c")
0
 
drichardsCommented:
That too being String.Format("{0:c}", calculatedTotalValue); - didn't see the intervening post.
0
 
NugsAuthor Commented:
Ok, one more Microsoft.VisualBasic conversion...

Dim NumberOfDaysDifference As Integer = DateDiff(DateInterval.Day, Convert.ToDateTime(strStartDate), Convert.ToDateTime(EndDate))

The original VB code is working out the number of days between the start and end date... What woudl the C# equivilent be?

Nugs
0
 
NugsAuthor Commented:
nevermind, something like this should work...

int NumberOfDaysDifference = ((TimeSpan)(Convert.ToDateTime(EndDate) - Convert.ToDateTime(strStartDate))).Days;

Nugs...
0
 
Bob LearnedCommented:
int numberOfDaysDifference = DateTime.Parse(startDate).Subtract(DateTime.Parse(endDate)).TotalDays;

Bob
0
 
NugsAuthor Commented:
Ohhh that one is cool....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now