Use the str() builtin, which:
Returns a string containing a nicely printable representation of an object.
E.g:
>>> import decimal
>>> dec = decimal.Decimal('10.0')
>>> str(dec)
'10.0'
Answer from Gareth Latty on Stack OverflowUse the str() builtin, which:
Returns a string containing a nicely printable representation of an object.
E.g:
>>> import decimal
>>> dec = decimal.Decimal('10.0')
>>> str(dec)
'10.0'
Use the string format function:
>>> from decimal import Decimal
>>> d = Decimal("0.0000000000000123123")
>>> s = '{0:f}'.format(d)
>>> print(s)
0.0000000000000123123
If you just type cast the number to a string it won't work for exponents:
>>> str(d)
'1.23123E-14'
Literally convert decimal to string
c# - Convert string to decimal, keeping fractions - Stack Overflow
String to decimal
Convert string to decimal keeping fractions.
Videos
Hmm... I can't reproduce this:
using System;
class Test
{
static void Main()
{
decimal d = decimal.Parse("1200.00");
Console.WriteLine(d); // Prints 1200.00
}
}
Are you sure it's not some other part of your code normalizing the decimal value later?
Just in case it's cultural issues, try this version which shouldn't depend on your locale at all:
using System;
using System.Globalization;
class Test
{
static void Main()
{
decimal d = decimal.Parse("1200.00", CultureInfo.InvariantCulture);
Console.WriteLine(d.ToString(CultureInfo.InvariantCulture));
}
}
Hello i was have the same issue, but it is easly, just do this:
string cadena="96.23";
decimal NoDecimal=decimal.parse(cadena.replace(".",","))
I think this is beacuse the notation that accept C# on decimal numbers are with a ","
Lets say i have this string
string s = "33.000";
i need to convert it to decimal with this format
decimal d = 33.000;
I am doing convert.toDecimal but receive decimal formating like this 33.00 so i lost last zero. any idea?