david.young Posted July 23, 2010 Share Posted July 23, 2010 I know this should be easy but it's not happening. When data has an amount in the decimal the client wants to keep it, $123.45 If it's just zero's they want to delete them, $123.00 would return as $123 Thanks Dave FP 5.8 Win XP sp 3 Acrobat 8 Link to comment Share on other sites More sharing options...
esmith Posted July 26, 2010 Share Posted July 26, 2010 var amount = Field("Value"); //your field if (Right(amount, 2) == "00") return Left(amount, amount.length - 3); else return amount; Link to comment Share on other sites More sharing options...
david.young Posted July 29, 2010 Author Share Posted July 29, 2010 Eric, I tried your rule doesn't seem to work. I will try some variations and see what I can do Thanks Dave Link to comment Share on other sites More sharing options...
Dan Korn Posted July 29, 2010 Share Posted July 29, 2010 return FormatNumber("$0.##", StringToNumber(Field("YourFieldName"))); Link to comment Share on other sites More sharing options...
david.young Posted July 29, 2010 Author Share Posted July 29, 2010 Thanks Dan, Unfortunatley all it returns is $0 Was I supposed to do anything more than add my field name? Thanks Link to comment Share on other sites More sharing options...
Dan Korn Posted July 29, 2010 Share Posted July 29, 2010 Unfortunatley all it returns is $0 Was I supposed to do anything more than add my field name? No, you should only have to replace the field name. Exactly what is in the data? Does it already have a dollar sign in it? If so, you can do this instead: return FormatNumber("$0.##", Trim(Field("YourFieldName")).replace(/^\$/,'')); Link to comment Share on other sites More sharing options...
david.young Posted July 30, 2010 Author Share Posted July 30, 2010 Hi Dan, Yes the dollar sign is in the data file. Your latest code returns the 2 zero's Thanks Dave Link to comment Share on other sites More sharing options...
esmith Posted July 30, 2010 Share Posted July 30, 2010 If you still need help, I'm thinking a snippet of your data file would help us "see the big picture." Link to comment Share on other sites More sharing options...
Dan Korn Posted July 30, 2010 Share Posted July 30, 2010 Sorry, try this: return Field("YourFieldName").replace(/\.0*$/,''); Link to comment Share on other sites More sharing options...
david.young Posted August 2, 2010 Author Share Posted August 2, 2010 Sorry Dan, .00 still shows up sample data file attachedto printable.zip Link to comment Share on other sites More sharing options...
Dan Korn Posted August 2, 2010 Share Posted August 2, 2010 Sorry Dan, .00 still shows up sample data file attached Okay, now I see. There's trailing white space in your data which is getting in the way. Try this: return Trim(Field("LGAmount")).replace(/\.0*$/,''); Link to comment Share on other sites More sharing options...
david.young Posted August 2, 2010 Author Share Posted August 2, 2010 Dan Thank You very much. That did it. What's with the trailing white space I've run into it before and it does'nt delete like a regular space? Dave Young Link to comment Share on other sites More sharing options...
Dan Korn Posted August 2, 2010 Share Posted August 2, 2010 What's with the trailing white space I've run into it before and it does'nt delete like a regular space? I'm not sure what you mean by "delete like a regular space." Sometimes white space is insignificant, such as when it's being interpreted by FusionPro's HTML-like tagged markup parser, but sometimes it is significant, such as in the regular expression in the code I posted. Basically, this code: return Field("LGAmount").replace(/\.0*$/,'');means "in the field value, if there's a period followed by zero or more 'zeros' at the end of the string, then replace all that with an empty string." When there's white space at the end of the field value, then that condition isn't true. So we need to use Trim to remove it first. Another way to fix this would be to modify the regular expression to take the trailing white space into account: return Field("LGAmount").replace(/\.0*\s*$/,'');This means, "in the field value, if there's a period followed by zero or more 'zeros' followed by zero or more white space characters at the end of the string, then replace all that with an empty string." For reference on regular expressions: https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.