Apologies for the tardy reply. Here is one way to show variable numbers of decimal places for the prices.I would like to display the prices with only one decimal instead of two.
I'll just show you how to do it for the first index or stock and you can make the chamges for your other stocks.
1) Firstly add the number of decimal places you want in the [Variables] section of MarketPrices.ini.
Code:
[Variables]DecPlaces1=2
Code:
[FormatPriceScript]Measure=ScriptScriptFile=FormatPrice.luaUpdateDivider=-1
Code:
[mIndex1_Price]Measure=WebParserUrl=[InfoIndex1]StringIndex=2;;>>-- add this line to take comas out of the price stringSubstitute=",":""
Code:
[cIndex1_PriceCalc]Measure=CalcFormula=[mIndex1_Price]*1
Code:
[LabelPrice1]Meter=STRINGMeterStyle= sTextRight | sColorSetGrayx=#Col2XPos#Text=[&FormatPriceScript:format_price( [&cIndex1_PriceCalc] , #DecPlaces1# )]
Code:
-- FormatPrice.lua-- adapted from http://lua-users.org/wiki/FormattingNumbers-- add commas to separate thousandsfunction comma_value(amount) local formatted = amount while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end return formattedend-- round number to nearest decimal placesfunction round(val, decPlaces) if (decPlaces) then return math.floor( (val * 10^decPlaces) + 0.5) / (10^decPlaces) else return math.floor(val+0.5) endend-- ------------------------------------------------------------- format_price formats output with comma to separate thousands-- and rounded to given decimal placesfunction format_price(amount, decPlaces ) local str_amount, formatted, famount, remain decPlaces = decPlaces or 2 -- default 2 decPlaces places famount = math.abs(round(amount,decPlaces)) famount = math.floor(famount) remain = round(math.abs(amount) - famount, decPlaces)-- add commas to separate the thousands formatted = comma_value(famount)-- attach the decimal places portion if (decPlaces > 0) then remain = string.sub(tostring(remain),3) formatted = formatted .. "." .. remain .. string.rep("0", decPlaces - string.len(remain)) end return formattedend
Post a screenshot when you've made the above changes for all your stocks and I'll decide whether or not to incorporate the changes into the DA version of MarketPrices.
Statistics: Posted by Mordasius — Today, 9:08 am