Sonam Nathani
Sonam Nathani

Reputation: 21

DevExpress Reports - Custom FormatString

I'm using devexpress reports to display some data. I want to format my strings for representing rates/cost on the report.

Example, I have 4 different rates to display: 0.01, 0.0085, 0.10, 0.5500

I want to display them as: 0.01, 0.0085, 0.10, and 0.55 - Basically, display the entire rate if there it encounters something like 0.0085 and display 0.55 instead of 0.5500.

I'm reading about the XRLabel.BeforePrint event to see how this can be done but was wondering if there was an easier way to handle this.

Thanks.

Upvotes: 2

Views: 980

Answers (1)

nempoBu4
nempoBu4

Reputation: 6621

You can simply use the combination of 0 and # format string placeholders, so your format string may looks like #0.00##.
Here is example:

var source = new List<Tuple<float>>();

source.Add(new Tuple<float>(0.01F));
source.Add(new Tuple<float>(0.0085F));
source.Add(new Tuple<float>(0.10F));
source.Add(new Tuple<float>(0.5500F));

var labelItem1 = new XRLabel();
labelItem1.DataBindings.Add("Text", null, "Item1", "{0:#0.00##}"); //<= Here comes the format string.

var detail = new DetailBand();
detail.Controls.AddRange(new XRControl[] { labelItem1 });

var report = new XtraReport();
report.Bands.Add(detail);
report.DataSource = source;

report.ShowRibbonPreview();

Upvotes: 1

Related Questions