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

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

Recommended Posts

Posted (edited)

I use a formula to round a number to 1 decimal point and put brackets around it before plugging it into a text document. This works fine for most numbers but it fails for numbers ending in zero. They are instead returned by the function without any decimal, 1 nothing instead of 1.0. That's a bug as far as I can see. If I specify 1 decimal point and get none from the function, I consider the code broken.

input:      numbers with variable decimal points, e.g. 2.345 and 1.0
formula:    "(" & Round ( final grade ; 1 ) & ")"
output:     2.3 (correct) and 1 (incorrect)
expected:   2.3 and 1.0

How can I work around this? I'm running FM Pro 12 Advanced.

Edited by jax
Posted
13 minutes ago, jax said:

That's a bug as far as I can see.

No, it's not a bug at all. The result of the Round() function is a number. A number does not have trailing (or leading) zeros. If you want to format the number to always display one decimal digit, you can use:
 

Let (
r = Round ( final grade ; 1 )
;
Int ( r ) & SerialIncrement ( ".0" ; 10 * Mod ( r ; 1 )  )
)

which calculates a text result.

  • Like 2
Posted

Thanks comment. Works like a charm.

I interpreted this differently since in my work as a scientist 1.0 means you are sure about the decimal. 1 means you have no idea whether it's 1.0 or 1.4. This is why I expected Round (number;1) to also return a zero.

Posted

Hey comment, just wanted to say, that function using SerialIncrement is awesome.

I had never seen that function before (introduced in FileMaker 7), but now plan to find a way to use it very soon. Great technique.

Posted
5 hours ago, jax said:

in my work as a scientist 1.0 means you are sure about the decimal.

I understand that but I don't think it's feasible, in a general computing language, to keep track of every number's value and precision. You would also have to modify the arithmetic rules applied to these numbers.

  • 2 weeks later...
Posted

Admittedly I'm a noob wading around in the deep end of the pool, but can't you use the data tab on the Inspector to set the number of decimal places to 1?  The underlying data in the Table doesn't change from what was entered so the accuracy isn't altered, but the display is now in the format I think you are looking for (You entered 1.0 and it will display as 1.0).

hth

Posted

Yes Guy, the data formatting options in the Inspector are often all that's needed. The exceptions are things like merging a decimal number into a block of text for an email or whatever, which sounds like what the goal is here.

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