# GetAsNumber Gotcha

**URL:** <https://the.fmsoup.org/t/getasnumber-gotcha/2825>\
**Category:** Heads-Up!\
**Tags:** functions, calculations, filemaker\
**Created:** [March 26, 2022, 4:10pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825 "2022-03-26T16:10:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [March 26, 2022, 4:10pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/1 "2022-03-26T16:10:29Z")

</div>

I may be late to the game… but I just came across a gotcha I thought would be good to share.

GetAsNumber returns the numerical characters in a given string. In essence, this function is equivalent to Filter (textToFilter; "0123456789"), only the return value is a number and not text.

There is an exception. GetAsNumber ("?") returns the question mark character instead of an empty value. I speculate the reason is because FileMaker uses the question mark character as a return value for some functions to indicate an error condition and Claris wants to ensure the error condition propagates throughout this function.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [March 26, 2022, 6:03pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/2 "2022-03-26T18:03:20Z")

</div>

The take-away is to do precautionary testing of content. Especially as the presence of a question mark in the data for maths wins.

`Let ( price = "?" ; 10 * price ) // result is "?"`

In simple tests, summary fields ignore a question mark or treat it as zero.

ExecuteSQL() statements use question marks in a completely different way. They are placeholders for parameters. It should be possible to contrive a way to create unexpected behaviour in an ExecuteSQL statement by passing in a question mark instead of a text or number value. That would "steal" one of the parameters, causing the following parameters to be mismatched.

---

<div class="post-metadata">

**Author:** ![ByteTheBullet](https://avatars.discourse-cdn.com/v4/letter/b/e56c9b/32.png) [@ByteTheBullet](https://the.fmsoup.org/u/ByteTheBullet)\
**Post date:** [March 30, 2022, 2:16pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/3 "2022-03-30T14:16:21Z")

</div>

One common test I've used is to compare the field with a GetAsNumber(field). If they're not the same, you know you may have a data issue.

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [March 30, 2022, 2:29pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/4 "2022-03-30T14:29:31Z")

</div>

Not necessarily. You may simply want to strip non-numeric characters from a string.

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [March 30, 2022, 3:47pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/5 "2022-03-30T15:47:41Z")

</div>

Happy Birthday @bdbd 🍾

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [March 30, 2022, 4:32pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/6 "2022-03-30T16:32:12Z")

</div>

I struggled with, and eventually gave up on `GetAsNumber( MyTable::MyField ) = MyTable::MyField` as a test for detecting non-numeric data entry. (My use case was to allowing the user to do their data entry in a set of global fields, and then validate their input before saving it to a record.)

1. If MyField is data-type number, and someone enters something like `123hello`, then the above test returns a True result, but I want a test that flags the `123hello` value as non-numeric.

2. If MyField is data-type text, and someone enters something like `12.00` or `100000000000000000000000` then the above test returns a False result, but I want a test that does not flag these as non-numeric.

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [March 30, 2022, 5:06pm UTC](https://the.fmsoup.org/t/getasnumber-gotcha/2825/7 "2022-03-30T17:06:34Z")

</div>

> [@bdbd](#):
>
> GetAsNumber returns the numerical characters in a given string. In essence, this function is equivalent to Filter (textToFilter; "0123456789"), only the return value is a number and not text.

I made an error in the original post. The equivalent I gave does not take into account a thousand separator nor a decimal separator… and these are locale dependent. Filter (textToFilter; "0123456789 ,.") would be more accurate… though not perfect. Anyhow… my point was not on the Filter function but the GetAsNumber function. Hope my inaccuracy is OK in this context.
