[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

round it to .99

Hello,

I am doing some calculation to find the produt price, after doing the calculation I would want the total cost to end as .99

for ex: Return (valel / 1.9) +  ((13.95 / 1.9) + (56 + 1.9))  X 9

if the result for the above come as 54.30 then I would want it to come as 54.99

or 54.01 to 54.99
or 54.98 to 54.99


Can someone please help in this?

Thanks
C
0
charlie324
Asked:
charlie324
  • 5
  • 3
  • 2
  • +3
4 Solutions
 
Alfred A.Commented:
Hi,

You can try the following:

Return Math.Ceiling((valel / 1.9) +  ((13.95 / 1.9) + (56 + 1.9))  X 9) - 0.01
0
 
quizwedgeCommented:
Alfred1's solution should work.  The way I would probably do it is:

Return CInt((valel / 1.9) +  ((13.95 / 1.9) + (56 + 1.9))  X 9) + 0.99
0
 
charlie324Author Commented:
Thanks folks, the curect statment is this, please can you advise if i can still round it as desired..


 Return Math.Round(((actual / 1.4) + 2 + ((14.95 / 1.4) / moq) + (7.5 / 1.4)) * 2, 2)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Alfred A.Commented:
Yes.  @quizwedge's solution should work as well. :-)

The approach is just different.
0
 
charlie324Author Commented:
If I use this

 Return CInt(((actual / 1.4) + 2 + ((14.95 / 1.4) / moq) + (7.5 / 1.4)) * 2) + 0.99

I am getting 86.99 instead of 85.99

and when I use this

 Return Math.Ceiling(((actual / 1.4) + 2 + ((14.95 / 1.4) / moq) + (7.5 / 1.4)) * 2) - 0.01

then its 85.99 as desired...


0
 
charlie324Author Commented:
values are

 Return Math.Ceiling(((34.73/ 1.4) + 2 + ((14.95 / 1.4) / 1) + (7.5 / 1.4)) * 2) - 0.01

would this method gives me correct values at all times?

please advise

tahnks
0
 
rajapandian_81Commented:
Use  Math.Floor like below

double d = 54.01;
        d = Math.Floor(d) + 0.99;

Open in new window

0
 
Alfred A.Commented:
Hi,

Oh yeah.  Didn't notice that one.  :-)
0
 
Alfred A.Commented:
Hi,

Yes.  That Math.Ceiling should do the trick.
0
 
Alfred A.Commented:
Hi,

By the way, why do you need to do this?

Return Math.Round(((actual / 1.4) + 2 + ((14.95 / 1.4) / moq) + (7.5 / 1.4)) * 2, 2)

Is there a reason behind the use of the Round since your requirement is to append a .99 cent value for each product price?
0
 
guru_samiCommented:
The above solutions will set all values with  .99....
What value do you want if it is whole number i.e. 54.00 ? go to 54.99 ?
Check this if you want 54.00 to remain 54.00

decimal x = 54.01m;
 decimal fract = x - Decimal.Truncate(x);
 if (fract > 0)
 {
            x = Decimal.Truncate(x) + 0.99m;
  }
0
 
Tech_StigCommented:
You can also use mod to get the remainder and then add the difference from 0.99 to the original total.

Dim val as Double = 53.30
val += 0.99 - Math.Round(val Mod 1, 2)

However, as guru_sami mentioned this will always round up to 0.99. If a value is 53.00 it will become 53.99. If that is not the expected output then you would need something like this:

        Dim val As Double = 53.01
        If (val Mod 1) > 0 Then
            val += 0.99 - Math.Round(val Mod 1, 2)
        End If
0
 
quizwedgeCommented:
Not sure why mine didn't work, but go ahead and use one of the other ones.  I was just offering another method in case doing it that way made more sense to you and scored me a few points. :)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now