Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am crating one application
I want to round of the given/Calculated amount.

if the calculated amount is 1.2 then it gives 1

Math.Round(95.55)

output is 96

but when i use the
Math.Round then it show 2 when the calculated amount is greater than 1.5

but i want

input is 1.2 then output is 2

Please help me...
Thanks in advance..
Posted
Updated 25-Nov-13 2:32am
v2

The correct (verified) output of Math.Round is
  • 1.0 when input is 1.2
  • 96 when input is 95.55

They are different from the ones you reported.

[update]
Quote:
I want round value when the entered value is 1.01 then it show 2
i want like this ..
is it possible
Yes, it is possible: use Math.Ceiling[^] instead of Math.Round.

[/update]

[update 2]
Quote:
hi, i am tried "Math.Ceiling" but it gives out same as a "Math.Round"

They do NOT give 'the same results', try:
VB
Dim a() As Double = {1.2, 95.55}
Dim ro(2) As Double
Dim ce(2) As Double


ro(0) = Math.Round(a(0))
ro(1) = Math.Round(a(1))
ce(0) = Math.Ceiling(a(0))
ce(1) = Math.Ceiling(a(1))

Console.WriteLine("ro(0)={0}, ro(1)={1}", ro(0), ro(1))
Console.WriteLine("ce(0)={0}, ce(1)={1}", ce(0), ce(1))


[/update 2]
 
Share this answer
 
v3
Comments
basurajkumbhar 25-Nov-13 8:21am    
Hi,
Thanks for reply,
I want round value when the entered value is greater than 1.01 then it show 2
i want like this ..
is it possible
basurajkumbhar 25-Nov-13 8:50am    
hi,
i am tried "Math.Ceiling" but it gives out same as a "Math.Round"
Dim ldblamount as double

ldblamount = val("100.01")

If Int(ldblamount) <> ldblamount Then
ldblamount = Int(ldblamount) + 1
End If


'Result
I Value Result
100.00 100
100.01 101
100.99 101
 
Share this answer
 
v4
Hi, am a new member on the site try this -Int(-1.2) works ok for me
 
Share this answer
 
have you tried this one:
VB
Math.Ceiling(Cdec(TextBox1.Text * 100) / 100D)

suppose that TextBox1.Text is the entered value.

Smile!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900