Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

How to validate that imported text contains two decimal places?


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

Recommended Posts

Posted

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.

Posted

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

Posted

Thinking about it, you should also check that if there is a minus sign, it comes at the beginning, not in the middle or at the end...

patterncount ( importfield , "-" ) = patterncount ( left(importfield,1) , "-" )

James

Posted (edited)

Take a look at this Thread Link that has a calculation by DJ, and comment. It can be modified in many ways to take the raw number and adjust it to your needs.

Lee

Edited by Guest
Posted

James, thank you.

That does help me get on a good track -- especially the point about being on the lookout for dual decimal points or minus signs.

Posted

I believe all these tests could be rolled into =


Exact ( Int ( text ) ; text )

or

Exact ( Int ( text ) & SerialIncrement ( ".00" ; 100 * Mod ( Abs ( text ) ; 1 ) ) ; text )

Not sure what's the purpose here, though. 46.2 or 46.875 are perfectly valid numeric values.

Posted

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.

This topic is 5542 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.