I am trying to replace a comma in a string.
For example, the data is the currency value of a part.
Eg. 453,27 This is the value I get from an SAP database
I need to replace the comma to a period to fix the value to the correct amount. Now sometimes, it will be in the thousands.
Eg. 2,356,34 This value needs to be 2,356.34
So, I need help manipulating the string to replace comma that is 2 characters from the end.
Thanks for the help
A quick google search gave me this:
So your "charToUse" should be '.'. If it always is 2 characters from end, your index should be text.length - 3.
http://www.dreamincode.net/code/snippet1843.htm
Use this :
You'll need to add a bit of checking for cases where there are no commas in the string, etc. but that's the core code.
You could also do it with a regex, but this is simple and reasonably efficient.
If I understand correctly, you always need to replace the last comma with a period.