Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to validate that imported text contains two decimal places?

Featured Replies

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.

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

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

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

  • Author

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.

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.

  • Author

... is supposed to contain a dollar amount.

Just to clarify, the problem is that 46.2 and 46.875 represent key entry errors.

OK, but if someone can enter "12.3" or "12.345" instead of "12.34", then they can just as easily enter "12.43" or "1234" - so this method is neither here nor there.

What is the next step?

How do you know what the correct number should be?

Lee

  • Author

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.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.