Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6029405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:52:52+00:00 2026-05-23T04:52:52+00:00

While Converting Decimal to String, I tried two methods. Method 1: string a =

  • 0

While Converting Decimal to String, I tried two methods.

Method 1:

    string a = "100.00", b = "50.00";
    string Total = (string)(Convert.ToDecimal(a) + Convert.ToDecimal(b));

It throws error, cannot convert Decimal to String.

Method 2:

    string Total = (Convert.ToDecimal(a) + Convert.ToDecimal(b)).ToString();

It doesn’t throw error and it is working fine.

I want to know the difference between these two methods of Conversion and Why it throws error when I used Method 1?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:52:52+00:00Added an answer on May 23, 2026 at 4:52 am

    The first method is trying to take a decimal (the result of adding the 2 decimals) and cast it as a string. Since there’s no (implicit or) explicit conversion from decimal to string, it throws because of the mismatch.

    The second one takes a decimal and calls a ToString() method on it – since ToString is a valid method on the decimal type, this makes a normal instance method call and you get the return value of that call, which is a string.

    Since you’re using Convert calls already, you might find it more natural to do Convert.ToString to get the decimal back to a string.

    It might be more clear if you separate the ‘add two decimals’ to a separate local var, since that’s common to both here.

    So, the (commented out) total1 fails because it’s trying to just cast, and we have no conversion available to do so. The latter two both work fine, since they are method calls that are returning a string.

    string a = "100.00", b = "50.00";
    decimal result = Convert.ToDecimal(a) + Convert.ToDecimal(b);
    //string total1 = (string)result;
    string total2 = result.ToString();
    string total3 = Convert.ToString(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
While decoding,I am getting NSData bytes by decoding a string.I am converting NSData bytes
I've got a problem converting an object property to string while using reflection... string
I know how to convert binary to decimal. I know at least 2 methods:
I need to convert MimeMessage into byte array, but while converting some characters are
I have, double d = 0.005; d = d/100; string str = Convert.ToString(d); output
While converting a zip file to base64 encoded string,Which is needed to sent mail
While converting an app to use Automatic Reference Counting I came across this error:
While converting types, I have found myself using both VB functions and BCL Convert.To*
While converting an old code, I encountered the following problem. Given an HTML string,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.