Reputation: 55
What would be the easiest way to convert a decimal to string, and add a comma and spaces. It has to convert land parcels area, in square meters. It can be 1456, 25678, 364789 or 2548978 m².. It depends on the size of the parcel. I'd like to convert it to obtain this result :
1456 = 1 456,0
25678 = 25 678,0
364789 = 364 789,0
2548978 = 2 548 978,0..
I tried this :
myvalue = Convert.ToDecimal(MyFeature.Value(MyFeature.Fields.FindField("MyAreaField"))).ToString("# ### ###,0")
But 312410 gave this result : 31 2 410
Can you help me please?
Upvotes: 0
Views: 88
Reputation: 55
I found this, and it work
Dim nfi = New NumberFormatInfo() With { _
.NumberGroupSeparator = " ", _
.NumberDecimalSeparator = "," _
}
Convert.ToDecimal("1231231232").ToString("#,#.0#", nfi)
Convert.ToDecimal("123456,1").ToString("#,#.0#", nfi)
Convert.ToDecimal("123456").ToString("#,#.0#", nfi)
Convert.ToDecimal("123").ToString("#,#.0#", nfi)
It gives this :
1 231 231 232,0
1 234 561,0
123 456,0
123,0
Upvotes: 0
Reputation: 923
Try this instead:
var myValue = Convert.ToDecimal(MyFeature.Value(MyFeature.Fields.FindField("MyAreaField")));
var sValue = string.Format("{0:0 0,0}", myValue);
Upvotes: 2