Formating the numbers in TLegend

Dear experts,
I have a plot and I create a legend for it including some numbers (yields). the numbers are shown with 6 digits after the decimal point. I would like to format the numbers shown in my Legend to show one digit after decimal point.
example: 152.600000 → 152.6

Thank you for the help

Can you post the code creating the legend ?

Hi @couet
Thanks for the quick response. Here is the code:

std::string BMassCTitle = "B-Mass Corresponding to Different B-Vertex Probabilities";
	TCanvas* BMass_canv = new TCanvas("BVertexProbability_BMass",BMassCTitle.c_str());
		BMass_canv->SetWindowSize(WW, WH);
		BMass_canv->SetGridx();
		BMass_canv->SetGridy();
		gStyle->SetOptStat(0);
		Functions[0]->SetTitle("B-Vertex Probabilities");
		Functions[0]->GetXaxis()->SetTitle("M_{B}(GeV)");
		Functions[0]->GetXaxis()->SetRangeUser(5.08, 5.48);
		Functions[0]->GetXaxis()->SetNdivisions(8);
		Functions[0]->GetYaxis()->SetRangeUser(0,(Functions[0]->GetMaximum()+0.1*(Functions[0]->GetMaximum())));
		Functions[0]->SetLineColor(1);
		Functions[0]->SetFillColor(1);
		Functions[0]->SetFillStyle(3001);
		Functions[0]->Draw("LF2");
		for (int i=1; i<(int)Functions.size(); i++) {
			int Color = i+1;
			if (Color==10)
				Color = 46;
			Functions[i]->SetLineColor(Color);
			Functions[i]->SetFillColor(Color);
			Functions[i]->SetFillStyle(3001);
			Functions[i]->Draw("LF2,SAME");
		}
	TLegend* BMass_l = new TLegend(0.75,0.60,0.95,0.85);
		BMass_l->SetTextSize(0.015);
		BMass_l->SetNColumns(3);
		BMass_l->SetHeader(BMassCTitle.c_str(),"C");
		for (int j=0; j<(int)Functions.size(); j++) {
			BMass_l->AddEntry(Functions[j],("VtxProb_{B} > "+to_string(BVtxStart+(j*BVtxStep))).c_str(),"l");
			BMass_l->AddEntry((TObject*)0,("SY = "+to_string(Yields[j].first.first)+" +/- "+to_string(Yields[j].first.second)).c_str(),"");
			BMass_l->AddEntry((TObject*)0,("BY = "+to_string(Yields[j].second.first)+" +/- "+to_string(Yields[j].second.second)).c_str(),"");
		}
		BMass_l->Draw();
	BMass_canv->Update();

In the above code, Functions is an array that contains TF1* objects.

in your example to_string does the conversion to string. I am not sure you can specify the formatting for to_string

Use: c++ - Set precision of std::to_string when converting floating point values - Stack Overflow
or: std::format in C++20 – MC++ BLOG if you can use C++20

The reason I used to_string() is because I thought I can only use strings in the AddEntry method.
Is it possible to format before turning into string? or just not use strings?

Try what ferhue suggested, or you can also use Form; e.g. if val is a double and you want 1 decimal:

BMass_l->AddEntry(mygraph,Form("%.1f",val),"l");

Hi @dastudillo,
That worked perfectly!
Thank you all for your help.