Jump to content

Decimals, keep some delete some


Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...