Decimal minimums and Maximums using .NET Reports

STGI-01STGI-01 Member Posts: 3
edited 2012-01-24 in NAV Three Tier
Hello,

Was trying to figure out how to best go about solving this problem. We have a customer who has prices that occasionally will need 3 decimal places. They want to print only when the 3rd decimal place is actually <> 0. So for example.

1.50
or
1.505

The first prints because the price is only $1.50, the second the price is $1.505. They want them to print exactly that way. Anyone seen anything on how to do this in .NET? Currently everything we have done in .NET requires it to either be 2 or 3 decimals, not a variable amount.

Comments

  • deV.chdeV.ch Member Posts: 543
    To create a string if eigthter 2 or 3 decimal places you could use the method suggested in this link:
    http://stackoverflow.com/questions/6092243/c-sharp-check-if-a-decimal-has-more-than-3-decimal-places
    Detext if the decimal has 3 decimal places then format it that way (#.000) otherwise (#.00)

    Does that help you?

    EDIT: What do you mean by .NET Reports? RDLC Reports use ind Navision? If so we're talking about another thing ;)
  • ThomasHej_MSFTThomasHej_MSFT Member, Microsoft Employee Posts: 14
    In .NET you can easily format a decimal or float by using ToString(string format)

    I read your question as:

    If the number has 2 or less decimals I want to format is as X,XX (e.g 1,55 // 3,50 // 7,00)
    If the number has 3 decimals (or more), I want to format the number as X,XXX (e.g 1,123)

    The above can be done like this in .NET (C# and VB)
    static void Main(string[] args)
            {
                decimal d = 2.3m;
                string s = d.ToString("0.00#");
    
                //  1       ->  1.00
                //  2,3     ->  2.30
                //  3,33    ->  3.33
                //  4,333   ->  4.333
                //  7,3333  ->  7.333
    
                Console.WriteLine(s);
                Console.ReadLine();
            }
    

    I'm not quite sure if this is what you were looking for, if not - just yell...
    Thomas Hejlsberg
    CTO, Architect - Microsoft Dynamics NAV
  • STGI-01STGI-01 Member Posts: 3
    deV.ch wrote:
    To create a string if eigthter 2 or 3 decimal places you could use the method suggested in this link:
    http://stackoverflow.com/questions/6092243/c-sharp-check-if-a-decimal-has-more-than-3-decimal-places
    Detext if the decimal has 3 decimal places then format it that way (#.000) otherwise (#.00)

    Does that help you?

    EDIT: What do you mean by .NET Reports? RDLC Reports use ind Navision? If so we're talking about another thing ;)


    Yes, my apologies, so used to calling them .NET on our side, but I am talking about RDLC Reports for use in Nav 2009 R2.
  • deV.chdeV.ch Member Posts: 543
    just set the DecimalPlaces Property to 2:3 and on the RDLC Side set the Format Property of the TextBox to "Field!<DataSetFieldName>Format.Value"

    if setting decimalplaces property is not working on classic and on rtc side, you are maybe using AutoFormatExpr which ignores the DecimalPlaces feature.

    @ThomasHej_MSFT Thanks for the info! It must have been friday... ](*,) Of course this is the right way to do such thing in .net
Sign In or Register to comment.