Link to home
Start Free TrialLog in
Avatar of Nugs
Nugs

asked on

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
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of drichards
drichards

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.
Avatar of Nugs

ASKER

I basically need to convert calculatedTotalValue to a currency format with 2 decimal places.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nugs

ASKER

Original code does not work in C#...
Avatar of Nugs

ASKER

What about: Session["TotalCost"] = String.Format("{0:c}", calculatedTotalValue);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That too.  It's just a longhand version of calculatedTotalValue.ToString("c")
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nugs

ASKER

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
Avatar of Nugs

ASKER

nevermind, something like this should work...

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

Nugs...
int numberOfDaysDifference = DateTime.Parse(startDate).Subtract(DateTime.Parse(endDate)).TotalDays;

Bob
Avatar of Nugs

ASKER

Ohhh that one is cool....