Newbies GrandpaGrrr Posted February 27, 2008 Newbies Posted February 27, 2008 The setup: I'm in the process of building an invoice system for a computer repair company. On the actual invoices some products are covered under warranty and have a custom code for the total. Some products leave the shop with no charge, which also has a custom code. Everything else has a dollar amount. I have a Total field which is defined as text so that the custom codes can be entered. The majority of time there will be a number total in $, but sometimes there will be the custom code. Thus the text field definition. The problem I'm having is that I can't seem to get the calculations to keep the trailing zero on amounts like $89.50. I don't want to write a huge case statement, or loop just to keep a zero on the end of an amount. And to this point I've not found a solution which allows me to format this field as a number with set decimal places when a number is in the field. Any suggestions you might have would be helpful.
comment Posted February 27, 2008 Posted February 27, 2008 (edited) I got a bit lost in your explanation, but in any case you can add trailing zeros to a number this way: Int ( Amount ) & "." & Right ( "00" & Amount * 100 ; 2 ) Note that this assumes Amount is rounded to 2 decimal places. --- And not negative. Edited February 27, 2008 by Guest Forgot to mention the negative part.
Newbies GrandpaGrrr Posted February 27, 2008 Author Newbies Posted February 27, 2008 Thanks that is exactly what I needed.
T-Square Posted February 28, 2008 Posted February 28, 2008 Comment-- I think that the decimal portion of your calc could be simplified to: Right ( Amount * 100 ; 2 ) since you're moving the decimal point to the right two spaces by the multiplication. [i acknowledge the left-padding principle for this sort of thing in general; this example wouldn't need it, though.] David
comment Posted February 28, 2008 Posted February 28, 2008 I'm afraid that wouldn't work when Amount is between 0 and 0.09 (inclusive). True, it could be 'simplified' by using "0" instead of "00", since one zero is the most you'll ever need to pad. But the extra zero adds no complexity, and I like it better this way because it makes the purpose of the calc stand out. Perhaps it would be better to use the dedicated function Filemaker provided for this very purpose: SerialIncrement ( "00" ; 100 * Mod ( Amount ; 1 ) )
T-Square Posted February 28, 2008 Posted February 28, 2008 Once again, I am proven wrong! And here I thought I was being so smart. David
Recommended Posts
This topic is 6183 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 accountSign in
Already have an account? Sign in here.
Sign In Now