[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# String to Decimal

Posted on 2009-07-12
5
Medium Priority
?
762 Views
Last Modified: 2013-12-17
Hi,

I'm getting an xml message with this value:
<Value>55.55<Value/>

I keep it in a string variable;

When I convert this to decimal, it gets converted to 5555 (not 55,55!)
decimal d = (decimal)str;

How can I convert this into 55,55 (not 5555) ?

Thank you guys!
0
Comment
Question by:Endelm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Accepted Solution

by:
iUsername earned 1200 total points
ID: 24835127
string s = "55.55";
decimal d = decimal.Parse(s);

decimal d is 55.55
0
 
LVL 12

Assisted Solution

by:expertsoul
expertsoul earned 800 total points
ID: 24835488
To convert a string to decimal you can use any of these methods:
string s = "55.55";

decimal d  = decimal.Parse(s); (as above, it works only with string)

decimal d;
 if(decimal.TryParse(s, out d)){
         //if s is a valid decimal string.
 }
 else{
        //if s is in different format.
 }

decimal d  = Convert.ToDecimal(s); (works with various datatypes)

0
 
LVL 3

Expert Comment

by:eirikurh
ID: 24836114
use InvariantCulture if your server has , as a decimal seperator

decimal.Parse("55.55", CultureInfo.InvariantCulture);
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 24837374
In your XML you show 55.55 (with a decimal point). At other places within your question your show 55,55 (with a comma). If its a comma in your XML then this is the reason it converts to 5555. Replace this with a decimal point.
0
 

Author Closing Comment

by:Endelm
ID: 31602601
Thanks guys! :)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question