vrdiver wrote:Crude, but it works. Just remember to keep an eye on 42TE in case it increases in value 100-fold some day
I've also hit the same problem and have come up with a solution. Its in python rather than VB, but should be easy to port over.
I've got a function to determine the magnitude of a number in a cell ie 9=1, 99=2, 999=3, etc
Code: Select all
def GetMagnitude(Price):
return int(math.log10(Price)+1)
Before updating the price in a cell, I check what number is in it and determine its magnitude:
Code: Select all
CurrentCellValue = sheet.getCellRangeByName(cell).Value
ExpectedMagnitude = GetMagnitude(float(CurrentCellValue))
Then, after fetching a price, I compare the magnitude of the fetched price (Price) with that of what was in the cell before. Correcting it if they're different by shifting dps by the appropriate amount.
Code: Select all
def CheckPoundsPence(Price, ExpectedMagnitude):
"""
Somethimes Yahoo returns price in GBP instead of GBX. Correct for this.
Shift price so as it reflects the expected magnitude.
"""
# Determine magnitude of price ie 9.00=1, 99.0=2, 999.0=3
PriceMag = GetMagnitude(Price)
# Handles both Left and Right shifts. Honest.
if PriceMag != ExpectedMagnitude:
Price *= 10**(ExpectedMagnitude - PriceMag)
return Price
This works well, though will hit a problem if the share price goes from eg 99->100 (the code would then shift the value to be 10 instead). Hopefully doesn't happen too often, but if it does then manually changing it to be 100 should ensure it's OK on next fetch.
-0x3F