This is a migrated thread and some comments may be shown as answers.

Divide by Any Number Always Returns Zero

1 Answer 394 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 03 Jul 2012, 11:11 PM
OK, let's check this off as a first-time stupid newbie question, b/c that's what its got to amount to.

It's my first Telerik report that has a Table control in the detail section and it is bound to a data source. In column 1 of the table is the expression [= Fields.InvoiceNum] and I get an invoice number for every row when I preview the report.

In column 2 of the table, I had an expression that basically amounted to Field2 divided by Field3. But this would always return a zero on every row of the report during preview.

For the sake of testing, my expression is currently [= 1 / 3]. This still returns a zero. If my expression is [= 1 + 3], I get 4. If it is [= 1 - 3] I get -2. If it is [= 1 * 3] I get 3. But [= 1 / 3] always returns 0. If I wrap the expression with [= CDbl(1 / 3)] I still get a zero, and the formatting is {0:#.0000}. So what gives? What am I missing here?

Thanks,
Steve

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 04 Jul 2012, 08:44 AM
Hi Steve,

We've noticed that you divide integers and this will lead to an integer result. This is a standard .NET behavior, and an easy solution would be to cast your data to double data type with CDbl(System.Object) integrated Function as shown in the following expression example
=CDbl(Fields.Field2) / CDbl(Fields.Field3)

Regards,
Peter
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Michael
Top achievements
Rank 1
Iron
Iron
commented on 14 Mar 2023, 08:33 PM | edited

@Peter  Thanks for this! This one was driving me crazy!
Tags
General Discussions
Asked by
Brian
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or