We help IT Professionals succeed at work.

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

Nugs
Nugs asked
on
Medium Priority
360 Views
Last Modified: 2010-04-15
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
You shoulda looked at the result for ToString("c"):

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

Bob

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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.

Author

Commented:
I basically need to convert calculatedTotalValue to a currency format with 2 decimal places.
either ToString("c") or your original code will give you that.

Author

Commented:
Original code does not work in C#...

Author

Commented:
What about: Session["TotalCost"] = String.Format("{0:c}", calculatedTotalValue);
Session["TotalCost"] = calculatedTotalValue.ToString("#.##");

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

Author

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

Author

Commented:
nevermind, something like this should work...

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

Nugs...
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

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

Bob

Author

Commented:
Ohhh that one is cool....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.