rpaterick Posted June 22, 2010 Share Posted June 22, 2010 I need to trim data from the right. ex: 145.00 to 145 ex: 89.00 to 89 Basically the 3 right characters but display everything else after. thanks, Ryan Link to comment Share on other sites More sharing options...
Dan Korn Posted June 28, 2010 Share Posted June 28, 2010 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 More sharing options...
rpaterick Posted June 28, 2010 Author Share Posted June 28, 2010 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 More sharing options...
Dan Korn Posted June 28, 2010 Share Posted June 28, 2010 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 More sharing options...
rpaterick Posted June 28, 2010 Author Share Posted June 28, 2010 Thanks Dan! I'm going to try some of these and let you know how it goes. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.