• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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