Jump to content
Sign in to follow this  
Stuppy

Adding Leading and Trailing Zeros to an Entered Number

Recommended Posts

Hello

After a bit of help with adding leading and trailing zeros to a number that I enter in a field.

When I enter a number into field X I would like the following calculations to be made to change the field contents. It is a unit cost type number field, so there could be several decimal places (i.e. it could be 0.10 or it could be 0.102444 ). Obviously if a field is entered in a 'proper' currency format @ 2 decimal places (i.e. 1.10, or 0.35 ) then obviously nothing would need to be done to field contents.

Hope this makes sense.

If "1" is entered, I would like it to add 2 trailing zeros , like ".00" - so "1" would be come "1.00"

If "1.1" is entered, I would like it to add 1 trailing zero - so "1.1" would become "1.10"

If "0.1" is entered, I would like to to add 1 trailing zero - so "0.1" would become "0.10"

If ".1" is entered, I would like to add 1 leading zero AND one trailing zero, so ".1" would become "0.10"

If ".10" is entered, I would like to add 1 leading zero - so ".10" would become "0.10"

http://www.filemakertoday.com/com/sh...ll=1#post81565

That post did work kind of, but I don't really understand the calculation - I cannot get my head around the mod function.

To anyone who can help thank you. I would ask for my own education if its not too much trouble if you could explain how the calculation works. I hate not knowing how something works and just using it regardless.

Please be aware I really do not think (unless I am missing something ) that using the 'fixed decimal place' option under Data tab is going to work as as said above, the number entered could be 0.10 or .1 or .42555 etc. The decimal place will rarely be the same

I just want to ensure that whatever is entered in that box, is converted to a proper currency display with at least (but not limited to) 2 decimal places

Hpope that makes sense :D

Thanks to anyone who can offer any assistance.

Share this post


Link to post
Share on other sites

Please be aware I really do not think (unless I am missing something ) that using the 'fixed decimal place' option under Data tab is going to work as as said above, the number entered could be 0.10 or .1 or .42555 etc.

I don't see why it wouldn't work - it fits all your examples.

Keep in mind that displaying an entry of .42555 as 0.43 does not change the underlying value. That's usually a good thing.

Share this post


Link to post
Share on other sites

To have leading zeroes does not the field type need to be TEXT?

RW.

Share this post


Link to post
Share on other sites

I don't see why it wouldn't work - it fits all your examples.

Keep in mind that displaying an entry of .42555 as 0.43 does not change the underlying value. That's usually a good thing.

Because for instance - If I was to use that to place an order - and it displayed as 0.43 instead of 0.42555, and you're placing an order for 100,000 unit at that price, while the calc might be precise, visually if you see 0.43 @ 100,000 - and used the displayed, rounded figure of 0.43 to do a manual calculation - or using that price to give to a custom, it can make a massive difference in the cost.

I really hope that makes sense.

Thank you for your replys.

Share this post


Link to post
Share on other sites

it can make a massive difference in the cost.

Yes, it can. So which one do you want? If the price is .42555, then 100,000 units should cost 42,555 - no matter how the price is displayed. If you want the actual price to be .43, then you should round it to 2 decimal places. This too has no bearing on how the price is displayed.

Share this post


Link to post
Share on other sites

I'm obviously not explaining myself correctly.

I do not want to round the number, or change the intended amount, only - i want what is entered into the field to be formatted correctly.

So, if they enter 0.45555, then that would NOT need anything doing to it as it has a leading zero, and has at least 2 decimal places.

Likewise, 0.45 would be acceptable as it has a leading zero and 2 decimal places.

If .45555 was entered, then a leading zero would need to be added - 0.45555

If 0.4 was entered, then a trailing zero would be needed - 0.40

If .1 is entered, then a leading and trailing zero needs to be added - 0.10

If 4 is entered, then this would need 2 trailing zeros - 4.00

If 4.1 is entered, then 1 trailing zero is needed - 4.10

I don't want to round the number entered - it just needs to be formatted correctly.

So I need a calculation to check that there are at least 2 decimal places, and that it has a trailing zero if needed.

Thanks again for any help anyone can offer.

Share this post


Link to post
Share on other sites

Well, if you format the number as decimal, without checking the 'Fixed number of decimals' option, then you would get all of the above - with the exception of padding to a minimum of two decimals places. IMHO, it makes more sense this way.

More importantly, the alternative requires using a Text field with a somewhat complex auto-entered calculation (along the lines of what you already have) and will result in the field sorting incorrectly. So perhaps you should reconsider your options before proceeding.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

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