Conversion of Double from Excel

I am working on a small item to read through an Excel spreadsheet and enter info into a payment portal. The issue I am running into is the conversion of a currency column to string. I understand that UiPath reads the number as a Double, but when I read the row using Read Range and then cast that input to a String it appears to move the decimal.

For example, if the InvoiceAmount column value is $425.00, InvoiceAmount.ToString will input 4.25 in the portal field. $875 becomes 8.75, and so on. Just looking for the best practice on converting this; as I receive the spreadsheet from an external source I cannot manipulate how the data is saved internal to the workbook.

@jeremiah.logan
Hello,
you can try using the converting the your amount to the generic variable. try format value activity. dont provide direct value you can provide varible inside to value field.

Hi @jeremiah.logan

You can try this:

  1. In Assign activity:

digitString = System.Text.RegularExpressions.Regex.Match(InvoiceAmount.ToString, “(?<=\$)\d+”).ToString

  1. In Assign activity:

formattedNumber = digitString.Insert(1, ".")

Hope this helps,
Best Regards.

@jeremiah.logan

You can use read range with display values or preserve formatting…that way…it reads the values as you see on excel and not thw raw values

Hope this helps

Cheers

Thanks, all. I am sure all of the suggestions would do it, but just selecting the “PreserveFormat” option was an easy fix.

1 Like

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