Jump to content

How to validate that imported text contains two decimal places?


K1200

This topic is 5356 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I receive a line of text via an import that is supposed to contain a dollar amount. The agreed "convention" is that it will either be a whole number amount (like 46 or 5600) or will contain two decimal places (e.g., 46.20 or 5600.88). Any other value, like 46.2 or 46.875, is not acceptable and must be flagged as an import error.

Short of matching the parsed fractional amount against a value list of the 100 possible 2-digit decimals, is there a simple® way to validate this field?

Thanks in advance for any help.

Link to comment
Share on other sites

Yes. Use the code below in a calculation field (or a script step) to return your dollar value if importField is valid, or an empty result if importField is not valid.

if (

// check field contains only numbers, decimal points and minus signs

filter( importField ; "0123456789.-" ) = importField

and

// check there is exactly one decimal point

patterncount ( importField ; "." ) = 1

and

// check there is no more than one minus sign

patterncount ( importField ; "-" )

and

// check that the point is in third from the end

left ( right ( importField ; 3 ) , 1 ) = "."

, Getasnumber( importfield ) , "" )

Hope that helps.

James

Link to comment
Share on other sites

How do you know what the correct number should be?

Not to be trite, but it's not a problem of knowing what the number should be. Rather, the problem is to flag numbers that are obviously not dollar amounts. Yes, a transposition will be accepted, but an extra or missing digit in the fractional part won't be.

From the earlier suggestions, I think I'll be able to catch most of the entry problems most of the time.

Thanks for the assistance on this.

Link to comment
Share on other sites

This topic is 5356 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.