Override currency/number format in C# not working

Stimulsoft Reports.NET discussion
Post Reply
JoshS
Posts: 12
Joined: Thu Aug 11, 2022 4:38 am

Override currency/number format in C# not working

Post by JoshS »

I am trying to customise the currency formatting in code before rendering the report. Here is some sample code:

Code: Select all

var culture = new CultureInfo("de-DE");
var currencyFields = components.Where(x => x is StiText stiText && stiText.TextFormat is StiCurrencyFormatService).Select(x => x as StiText).ToList();

var format = new StiCurrencyFormatService(culture.NumberFormat.CurrencyPositivePattern, culture.NumberFormat.CurrencyNegativePattern, culture.NumberFormat.CurrencyDecimalSeparator, culture.NumberFormat.CurrencyDecimalDigits, culture.NumberFormat.CurrencyGroupSeparator, culture.NumberFormat.CurrencyGroupSizes[0], string.Empty, true, false, string.Empty);
currencyFields.ForEach(x => x.TextFormat = format);
Here's an example field

Code: Select all

<AmountValue Ref="102" type="Text" isKey="true">
              <AutoWidth>True</AutoWidth>
              <Brush>Transparent</Brush>
              <CanGrow>True</CanGrow>
              <ClientRectangle>68,0,2.72,0.6</ClientRectangle>
              <ComponentStyle>LabelValue</ComponentStyle>
              <Conditions isList="true" count="0" />
              <DockStyle>Left</DockStyle>
              <Margins>0,0,0,0</Margins>
              <MinSize>2.72,0</MinSize>
              <Name>AmountValue</Name>
              <Page isRef="9" />
              <Parent isRef="76" />
              <Text>{Items.Amount}</Text>
              <TextBrush>Black</TextBrush>
              <TextFormat Ref="103" type="CurrencyFormat" isKey="true">
                <DecimalDigits>2</DecimalDigits>
                <GroupSeparator>,</GroupSeparator>
                <NegativePattern>1</NegativePattern>
              </TextFormat>
              <TextOptions>,,,,WordWrap=True,A=0</TextOptions>
              <Type>DataColumn</Type>
            </AmountValue>
This override in code is working ONLY if I specify a currency symbol. If I leave currency symbol as string.Empty or " " etc. the default formatting of 2 decimal places, decimal separator ".", group separator "," is used instead.
Is this a bug? I would like to customise the number of decimal places, and not have the currency symbol at all, but still have all the other number formatting.

I have also tried doing the same but overriding NumberFormat, but this has the same issue.
Max Shamanov
Posts: 789
Joined: Tue Sep 07, 2021 10:11 am

Re: Override currency/number format in C# not working

Post by Max Shamanov »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
JoshS
Posts: 12
Joined: Thu Aug 11, 2022 4:38 am

Re: Override currency/number format in C# not working

Post by JoshS »

Hi Max, any update on this?
Max Shamanov
Posts: 789
Joined: Tue Sep 07, 2021 10:11 am

Re: Override currency/number format in C# not working

Post by Max Shamanov »

Hello,

You can set the report culture using this code:

Code: Select all

report.Culture = "de-DE";
Also you can use NumberFormat for text components instead CurrencyFormat

Thank you.
Post Reply