I am struggling to do somehting so simple in Crystal Reports

I have some numbers I.E
2.851
3.481
0.791

I want to round them up so they are
2.80
3.50
0.80

4
Contributors
3
Replies
23
Views
1 Year
Discussion Span
Last Post by Reverend Jim

Using `Math` can help you. Also your "2.80" is wrong it will be "2.90". Try this

`````` Dim core As Double = 3.481
REM: You can get or loop to your values using a loop instead of
' using just one example as I've done.
Dim RoundAwayFromZero As Double = Math.Round(core, 1, MidpointRounding.AwayFromZero)
Label1.Text = "The original value is: " & core & " The rounded value is: " & RoundAwayFromZero``````

I used a Label in my case.

Edited by Mr.M

If you are rounding up then your results should be 2.90, 3.50, and 0.80. IE, the first term is incorrect. There are standard algorithms for this which you can probably find in Wikipedia, such as this page: https://en.wikipedia.org/wiki/Rounding

Keep in mind that Math.Round exhibits (in my opinion) odd (no pun intended) behaviour. It behaves differently depending on whether the integer portion of a number is odd or even. For example

``````Math.Round(2.5) evaluates to 2.0
Math.Round(3.5) evaluates to 4.0``````

That's why I prefer to roll my own that always rounds x.5 up to the next integer. You can code this for any decimal place by multiplying by a factor of 10 and adding 0.5 before truncating. For example, to round 2.56 to one decimal

``````Multiply by 10 (to give 25.6)