Formatting decimal values if it has fraction - Invoke Code

Hi, i need to format numbers to pointed decimal numbers. i want to do it with Here is the code in Invoke Code activity;

Dim culINfo As New System.Globalization.CultureInfo(“tr-TR”)
Dim nfi As System.Globalization.NumberFormatInfo
Dim mySizes1 As Integer() = {3}
nfi = culINfo.NumberFormat
nfi.NumberGroupSizes = mySizes1
nfi.NumberDecimalSeparator = “,”
nfi.NumberGroupSeparator = “.”

'N2 means after dot two digits will allow. for example ;
'1234.56 ->“N2” → 1,234.56
'1234.56 ->“N3” → 1,234.560

Dim deger As Int32
Dim doubleDeger As Double
Dim str As String

For Each row As DataRow In io_dt.Rows

If (CDbl(row("Tutar")) - CInt(row("Tutar")) )>0 Then
	row("Tutar")=row("Tutar").ToString("N2", nfi)
End If

Next row

it gives me error which i couldn’t solve. my goal is to format from not pointed numbers to pointed numbers in a dataTable

this is a column in my dataTable which i want to format


the result i want to achieve ;


we faced also some times unclear results when forcing the formating to a specific culture format.

Have a look here and use it as a playground:
FormatNumbers_ToSpecificLocals.xaml (6.1 KB)

was producing this logs:

But keep in mind with a F2 the decimal part will be forced to .XX. Does mean for:
114460000 will be 114,460,000.00 e.g. dblDemoValue.toString(“N2”, nfi)

Kindly note: results from immediate panel (used for quick prototypings) can sometimes differ from watch panel /code /log message and is less meanfully

1 Like

Thank you so much for the effort Mr. Peter :slight_smile:

I gues German / Turkish formats on numbers are same . for Groups , for Decimal seperator
RnD were not done fully and confirmable but i guess a custom nfi leads to wrong formats (missing , on Groups). using nfi from CultureInfo works as we can see in playground xaml

Actually i need check for a condition like this ;

If (CDbl(row(“Tutar”)) - CInt(row(“Tutar”)) )>0 Then
row(“Tutar”)=row(“Tutar”).ToString(“N2”, nfi)
End If

as you can see, if my number has fraction it should be look like this 123.456,78

if my number has not fraction it should be look like this 123.456

Give a try on following condition

with the modulo function we can check if we do have fraction part or not

So we can toggle between N0 and N2


Hi Arif,

you can use the following code. See attachment
Sequence27.xaml (5.4 KB)
New Microsoft Excel Worksheet.xlsx (8.6 KB)

Best regards

1 Like

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