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
LVL 6
charlie324Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.