SupremeDud
SupremeDud

Reputation: 1421

crystal reports conditional formatting for summary fields

I'm trying to create a decimal formatting formula on my summary fields. The values in the database could have 0, 1, or 2 decimal places. I've started with this:

If (CurrentFieldValue mod 1 = 0) Then
            0
Else If (CurrentFieldValue mod .1 = 0) Then
            1
Else
            2

On a simple single data field, this works and displays the value with 0, 1, or 2 decimal places based on the data coming from my database. The same formula doesn't work for a summary field on my reports with group data. Any ideas?

Edit: Since I don't know how to format code in a comment, I'll address the suggestion of using a formula here:

Didn't work. Formula:

Sum ({myTable.dataValue}, {myTable.groupField})

then I used:

If ({@formula} mod 1 = 0) Then
    0
Else If ({@formula} mod .1 = 0) Then
    1
Else
    2

And I still got whole numbers for everything. My rounding is set to .01 with no formula. Do I need a formula for rounding too? I still don't understand why this works on individual values but not for group summaries.

Upvotes: 1

Views: 4865

Answers (2)

Lee Tickett
Lee Tickett

Reputation: 6037

OK- it turns out this is due to our lack of understanding of the mod function :)

Everything mod 1 actually returns 0. This is the formula you need to use:

if {ER100_ACCT_ORDER.ER100_ORD_TOT} * 100 mod 100 = 0 then
 0
else if {ER100_ACCT_ORDER.ER100_ORD_TOT} * 100 mod 10 = 0 then
 1
else
 2

:)

Upvotes: 2

Lee Tickett
Lee Tickett

Reputation: 6037

How about just creating a formula field instead of using the built-in summary field:

sum({mytable.myfield})

Then you can use your conditional formatting:

If ({@formula} mod 1 = 0) Then
        0
Else If ({@formula} mod .1 = 0) Then
        1
Else
        2

Upvotes: 1

Related Questions