Convert from String to Integer to Float and back again
As you read values off a site, there will come a time when you need to manipulate them, such as performing calculations or making comparisons. That doesn’t seem to be problem until you end up with Strings being compared to Integers. For the most part, a value read off a page will be a string because you don’t always know what it contains. For example, “New Sales Company” is a string of characters. On the other side, 537273 is a number. However, $537,273, which you can identify as numbers is actually a String value as far as the code is concerned. Even after you remove the dollar sign and comma, the value type will still be treated as a string because that’s how it was initially read. Comparing a string to an integer will cause a mismatch, but there is a simple way to handle that. The ValueOf() statement allows the comparison of values as a certain type. Taking the […]
Recent Comments