Jump to content

The TRIM feature


rpaterick

Recommended Posts

I'm assuming that you only want to do this trimming for numbers that are integer values (that is, which would otherwise end in ".00" instead of in ".47" etc.), and leave two digits for numbers which aren't. Try this:

var data = "145.00"
return Int(data) == data ? Int(data) : FormatNumber("0.00", data);

Link to comment
Share on other sites

I'm assuming that you only want to do this trimming for numbers that are integer values (that is, which would otherwise end in ".00" instead of in ".47" etc.), and leave two digits for numbers which aren't. Try this:

var data = "145.00"
return Int(data) == data ? Int(data) : FormatNumber("0.00", data);

 

Actually I'd like to do it for all values. I'm tricking the input value of the data for superscripting purposes. So if it did have a value, it would be another rule just to display the ".00" or ".47" and I can superscript that. Client submits data file that way.

Would that script work for values?

 

Thanks for your help Dan!

Link to comment
Share on other sites

Actually I'd like to do it for all values. I'm tricking the input value of the data for superscripting purposes. So if it did have a value, it would be another rule just to display the ".00" or ".47" and I can superscript that. Client submits data file that way.

Would that script work for values?

Okay, if you want to truncate all values to just the integer part, just do this:

var data = "145.47";
return Int(data)

Then for the other part that you want to superscript, something like this:

var data = "145.47";
return FormatNumber("00", (StringToNumber(data)-Int(data))*100);

Putting it all together:

var data = "145.47";
return Int(data) + "<superscript>" +
   FormatNumber("00", (StringToNumber(data)-Int(data))*100) + "</superscript>";

Of course, you can do the whole thing with regular expressions as well:

var data = "145.47"
return data.replace(/(\d+)\.(\d+)/, "$1<superscript>$2</superscript>");

Finally, if you want to always make sure it includes two digits in superscript, even their value is "00", do this:

var data = 145;
return FormatNumber("0.00", data).replace(/(\d+)\.(\d+)/, "$1<superscript>$2</superscript>");

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...