Adding a decimal to an Int32

I pull out some data from a PDF as a string and when I do, the decimal falls off the string.

example: instead of 699.32 it comes over as 69932

How do I add the decimal back in? It will always have 2 digits for the decimal so it should always go in the same spot.

You can’t have decimals on an integer. That’s literally what integer means - no decimals. Use the datataype “double” instead of integer. Double means decimal. Integer means whole numbers.

Thanks. When I make it a double, how do I get the decimal in? Long story short - when I extract from the PDF, it comes over with characters and then a number (i.e., Nassau699.32) so i then use Regex.Replace(acres,“\D+”,String.Empty) to remove the characters and that also removes the decimal.

Is there a better way to get rid of the characters?

Hi @atarantino

Use this expression to remove everything unless digit and decimal point

System.Text.RegularExpressions.Regex.Replace(acres, "[^\d\.]",String.Empty)

Hey

create a double type variable and try with this

yourdblvar = CDbl(Regex.Replace(inputString, "[^\d\.]",String.Empty))

Regards

Hi @atarantino

Your regex pattern is replacing the decimal point with ‘Nothing’. (preview it here)

image

Solution: You need to update your regex pattern.

The regex pattern (preview link) provided by @rikulsilva and @fernando_zuluaga (same pattern) will solve your problem.

Note: the decimal point is not highlighted.
image

Cheers

Steve

1 Like

this was perfect, thank you.

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