Parsing string to decimal

Hi

I have an excel file after reading it and storing in a data table the format is changing here i want to convert that string into a decimal format and write into another excel file

Example:
Input file After storing it into a data table Actual result i want
Amount Amount Amount
20000.00 20000 20000.00
12345.00 12345 12345.00

Thanks & regards,
A Manohar

1 Like

Hi @Manohar1,

Welcome to the Forum.:grinning:

As per my understanding you are getting amount as string and want it to be a decimal with two places. You can use the following syntax to your work done.
string.Format(“{0:0.000}”, Cint(amount)).

Regards,
Shiva karthik

Buddy @Manohar1
Welcome to uipath Community buddy

String.Format(“{0:0.00}”, row(Columnname)) and it worked buddy
image

Cheers @Manohar1

Thanks @Shiva_Karthik & @Palaniyappan

It didn’t work in my scenario where I am building a data table with datatype decimal for column Amount after formatting it is displaying in the same format where precision of two digits are not coming

Thanks & Regards,
A Manohar

Hi @Manohar1,

I did a small change in syntax. Please find the below screen shot and xaml file I have tested it and it is working.

Updated Syntax: sample.xaml (6.2 KB)
String.Format(“{0:0.00}”,CDbl(strAmount))

2 Likes

Hi @Shiva_Karthik

Getting the same result after changing the logic mentioned by you

image

please try with writing into a excel

Thanks & Regards,
A Manohar

Hi @Manohar1,

If you give something like 5000.00 it is writing only 5000 in excel but when you give an input like 5000.456 something it is writing 5000.45 correctly. I have attached the screenshot for both scenarios below kindly have look into it.

I am also attaching the code with excel writing part included along with excel sheet.

image
image
image

Regards,
Shiva Karthiksample.xaml (13.0 KB)
StrtoDec.xlsx (8.4 KB)

Hi @Shiva_Karthik

According to my requirement i want to store in that format only with precision of two digits ,even after last digit ending with zero.

when i changed the datatype to string I am able to print the result in a correct way but the cell format is coming in general in excel

Capture2

Thanks & Regards,
A Manohar

where as my output should be in the below format

Capture3

and the format that should i retain is

Capture4

Thanks & Regards,
A manohar

I am facing the same issue did you find any solution for this

@sathwik19

Yes I got the solution.
In my case i need the custom format #0.00 so that i have done following steps.
1.Make the Excel as visible.
2.send Ctrl+1 hot key ,it will open the format cell window.
3.click on custom method.
4.use type into and type #0.00
5.click on ok button.
6.send ctrl+s hot key for saving.

Regards,
A Manohar

Hi @sathwik19,

you can use below mentioned macro to format the numbers instead going through the front end.

Sub NumberFormat()
On Error Resume Next
Range(“A1”).Select
Selection.SpecialCells(xlCellTypeConstants, 1).Select
Selection.NumberFormat = “#,###”
Range(“A1”).Select
Selection.SpecialCells(xlCellTypeFormulas, 1).Select
Selection.NumberFormat = “#,###”
Range(“A1”).Select
End Sub

Regards,
Shiva Karthik