Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
hello i have this number 2.050.000 its not showing in table i use float
the problem with the second dot 2.050 this is ok but this 2.050.000 will not work ?
numbers like 65.233 is working ok but this number is not showing
is there any datatype i can use to make it work??

What I have tried:

i tried bigint but didn't work
Posted
Updated 3-Apr-17 23:59pm
Comments
Wessel Beulink 4-Apr-17 5:49am    
You are using dots?

The float range is: -3.4 × 1038to +3.4 × 1038. So 2.050.000 is not a problem. But I think you have dots in your numeric. Try to remove if so.
Jochen Arndt 4-Apr-17 5:57am    
"2.050.000" is not valid textual representation of a number that can be converted to a floating point value using the common text to number conversion functions.

With localisations where the decimal point is not the dot (e.g. the comma), the dots may be thousand separators. With your example the number would be then "2.050.000,0".

While you are handling floating point data types you have not to care about the decimal point character or thousand separators. But if you want to convert text to numbers or when printing numbers you have to take care of the localisation.

But without knowing about your data and the localisation it will be difficult to help.

1 solution

The trouble is that "2.050.000" is not a number as far as C# is concerned.
Although '.' is allowed as a "thousands separator" in several languages, C# does not use them at all, and insists that a number is written as "nnnnnn.dddd" where "nnnnnn" is the integer part, and "dddd" is the "fractional" part.
So if you number should be 2050000 then write it as 2050000.0.
If you have user entered values that include a thousands separator, then use double.TryParse to convert it:

double d;
string userInput = "2,050,000"; // My Locale uses a comma separator
if (!double.TryParse(userInput, out d))
{
Console.WriteLine("Not recognised");
}
else
{
Console.WriteLine(d);
}

Provided the user Locale is set correctly, that should parse the input in the desired fashion.
 
Share this answer
 
Comments
Member 13044689 4-Apr-17 6:06am    
actually this is code to sum between columns and double.parse not working some help

if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
string val1 = e.Row.Cells[13].Text;
string val2 = e.Row.Cells[14].Text;
string val3 = e.Row.Cells[15].Text;
string val4 = e.Row.Cells[16].Text;
Label lblTotal = (Label)e.Row.Cells[12].FindControl("Label20");
float _val1, _val2, _val3, _val4;

float.TryParse(val1, out _val1);
float.TryParse(val2, out _val2);
float.TryParse(val3, out _val3);
float.TryParse(val4, out _val4);
float sum = _val1 + _val2 + _val3 + _val4;
lblTotal.Text += sum.ToString();


the total column not show the number
OriginalGriff 4-Apr-17 6:27am    
So what - exactly - is in the val1, val2, ... and sum variables? Use the debugger, and check.
Why aren't you using the float.TryParse return value to check if the data was a valid number?
Member 13044689 4-Apr-17 7:28am    
it doesn't matter what value in it maybe will be empty or not but the problem that how can i sum using 2 dot value

ex: suppose val1 = 2,050,000
val2 = 3,000,000
sum = 5,050,000 ----------> but there is no value appear at sum col

and yes its working good when i try any numbers with 1 dot value so can u help?
OriginalGriff 4-Apr-17 8:31am    
Those aren't dots, they are commas - which means they are thousands separators.
Provided your Culture and Locale are set to accept them, TryParse will work.
It has an overload which allows you to specify the cultural info:
https://msdn.microsoft.com/en-us/library/0xh24xh4(v=vs.110).aspx
It may be worth your using that.

Use the debugger, check exactly what is happening. At the moment, you are guessing what the problem is, rather than looking at the evidence.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900