JCrocker Posted June 15, 2011 Share Posted June 15, 2011 My data is coming in as -1.01 and to represent a dollar amt savings and I'm trying to return $1.01 I got the dollar symbol by using the change number to currency rule so now I'm getting $-1.01 but I can't get rid of the - sign. Also I'm trying to figure out how to get -.98 in the same field to return as 98¢ Also in another field I have -25 to represent a percentage savings and I need to convert it to 25% by removing the - sign and adding the % sign. Any Suggestions Link to comment Share on other sites More sharing options...
Andre Globensky Posted June 15, 2011 Share Posted June 15, 2011 Hello JCrocker, just use this : return "$" + ReplaceSubstring( "-1.01" ,"-", "") You can change the "-1.01" for the your field Link to comment Share on other sites More sharing options...
JCrocker Posted June 15, 2011 Author Share Posted June 15, 2011 That works for -1.01 in particular. But how do I apply this rule to the entire external data field many different records and values. The values of less than a dollar that appear in the format of -.98 I need to return as 98¢ and the items of a dollar or more in the format of -1.56 i need to return as $1.56 . Both appear in the same field but different records so I'm guessing the rule must be written to address both? A similar scenario in a different field deals with a percentage savings. The data appears in the format of -27 and I need it to return 27% Link to comment Share on other sites More sharing options...
Andre Globensky Posted June 15, 2011 Share Posted June 15, 2011 Try something like this in a rule or a function in javascript globals : lcAmount = "-.98" if (Left(Trim(lcAmount),2) == "-.") { //return '¢'; return ReplaceSubstring(lcAmount,"-.","") + '¢'; } else { //return '$'; return '$' + ReplaceSubstring(lcAmount,"-",""); } for the percentage : lcPercent = "-27" return ReplaceSubstring(lcPercent,"-","") + '%'; Link to comment Share on other sites More sharing options...
JCrocker Posted June 16, 2011 Author Share Posted June 16, 2011 In javascript globals it gives me invalid return errors. It seems to want to work in a normal javascript text rule but it only gives me the same return everytime aside from the data. I need to link it to field30 for the dollar/cent amt and field31 for the percentage amt. Link to comment Share on other sites More sharing options...
Andre Globensky Posted June 16, 2011 Share Posted June 16, 2011 In your rule just replace the following var : lcAmount = Field("field30") same goes for the percentage lcPercent = Field("field31") if you want to go in javascript globals you have to declare the function and call it from any rule rule test with : return fixAmount(Field("amt")) in the javascript globals : function fixAmount(lcParameterPass) { lcAmount = lcParameterPass if (Left(Trim(lcAmount),2) == "-.") { //return '¢'; return ReplaceSubstring(lcAmount,"-.","") + '¢'; } else { //return '$'; return '$' + ReplaceSubstring(lcAmount,"-",""); } } Link to comment Share on other sites More sharing options...
JCrocker Posted June 16, 2011 Author Share Posted June 16, 2011 ah ok, i gotcha. When I plugged it all together It seems to work well Thank you for the explanation, sorry it took a minute i'm still learning as i go. Link to comment Share on other sites More sharing options...
Andre Globensky Posted June 16, 2011 Share Posted June 16, 2011 No problem, happy to have been of help. Make sure that your data as just '-.' at left position and the rest has '-' , i went with what you gave me here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.