Hope that this is what you are looking for:
string formatedOp = 2319000.6.ToString("#,##,##"); // 2,319,001
Here is a working example.
But still I don't get what you are going to deal with long?
if this for any specific reason means please include the reason so that I can update my answer. anyway you cannot store values with commas in long but you can print them with commas as like what I did in the above example.
Updates as per modified question: So your input contains some double values and you want them as in the specified format. I can suggest an option for this don't know whether it help you or not. anyway you can make a try:
Make the following changes in the properties:
- change long?
to double?
as your input is double.
- Include a readonly string property in the class which returns the specific string.
- Which will be updated when you set the double value.
In short the class will looks like the following after applying the following changes:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
private string _ActualSizeStr;
private double? _ActualSize;
public string ActualSizeStr
{
get { return _ActualSizeStr; }
}
public double? ActualSize
{
get { return _ActualSize; }
set
{
_ActualSize = value;
if (value.HasValue)
{
_ActualSizeStr = value.Value.ToString("#,##,##");
}
}
}
}
So when you assign a value(let it be 2319000.6
) for ActualSize
the _ActualSizeStr
will be updated with the required value(2,319,001
) so that when you retrieve or use those values make use of ActualSizeStr
instead for ActualSize
.