How to remove or limit decimal digit in WriteVal

Dear Members,

I would like to either remove decimal or limit the decimal to 2 digit from one of my below snippet,
however i am unable to do so even after trying by using round, prec and numtostri function as all these function works on printf but since i am using writeval to dispaly the result on chart i am unable to do so, any guidance would be appreciated.

Net_Buy_Vol  = round(((bp/tv)*V)/V*100);
Net_Sell_Vol  = round(((sp/tv)*V)/V*100);

Title = 
EncodeColor(colorWhite) + "   Buy Vol  = "+ EncodeColor(colorLime) + WriteVal(Net_Buy_Vol)+"%"+ 
EncodeColor(colorWhite) + "   Sell Vol  = "+ EncodeColor(colorRed) +  WriteVal(Net_Sell_Vol)+"%");

ABC

Why don't you simply read documentation of WriteVal/NumToStr?
Then you would see that there are more than one function arguments for both ones.
https://www.amibroker.com/guide/afl/writeval.html
https://www.amibroker.com/guide/afl/numtostr.html

NumToStr(Net_Buy_Vol, 1.0);

BTW, writeval is obsolete and should be replaced by NumToStr function.

Note: NumToStr is a synonym for WriteVal function and NumToStr is preferred in new coding.


IMO cleaner code is achieved by using StrFormat()

Title = StrFormat("%s   Buy Vol  = %s%1.0f%%%s   Sell Vol  = %s%1.0f%%", 
					EncodeColor(colorWhite), 
					EncodeColor(colorLime), 
					Net_Buy_Vol, 
					EncodeColor(colorWhite), 
					EncodeColor(colorRed), 
					Net_Sell_Vol); 
4 Likes

Thanks @fxshrat, never thought of using StrFormat().