Setting Decimal Format in select statement

Hi Guys,

Datatable :

Invoice AMOUNT
12345 9,897.58325
12346 5,180.56780
12347 3,700.73930
12348 3,885.09340
12349 53,197.30534
12350 49,023.15789

I’m using a select statement to get an array output, however, I’m having difficulty setting a format for decimal.
var_temp_dt.AsEnumerable().Select(Function (a) a.Field(Of String)(“Invoice”).ToString+“_”+
a.Field(Of Double)(“AMOUNT”).ToString).ToArray()

Expected output :
{
12345_9897.58,
12346_5180.56,
12347_3700.73,
12348_3885.09,
12349_53197.3,
12350_49023.15
}

please help me

Hi @Dmitri00007

Try this expression

(From D in Dt.AsEnumerable Let x=d(0).ToString+"_"+Convert.ToDouble(d(1).ToString).ToString("#.##") select x).ToArray

Regards
Sudharsan

If you dont want to round off the value checkout this expression @Dmitri00007

(From D in Dt.AsEnumerable Let x=d(0).ToString+"_"+System.Text.RegularExpressions.Regex.Match(System.Text.RegularExpressions.Regex.Replace(d(1).ToString,"\,","").ToString,"\d+\.\d{2}").ToString select x).ToArray

Hope this Helps!

Regards
Sudharsan

Hi @Dmitri00007 ,

Input
image

Output

Code

dt.AsEnumerable.Select(Function(x) x("Invoice").ToString+"_"+x("AMOUNT").ToString).ToArray

Thanks,

Hi @Dmitri00007

Check this code

dt.AsEnumerable.Select(Function(x) x("Invoice").ToString+"_"+Convert.ToDouble(x("AMOUNT").ToString).ToString("#.##")).ToArray

Thanks,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.