In this case the dollar sign is not coming from the code you have supplied. That will return a number without a symbol. Perhaps the symbol is in the code immediately before this code?
Do a site wide find using the regular expression:
That should find the $ symbols you need to replace