473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Get highest value from Math.Round

11
Hi..
I have tried following coding to get highest value.
EX: If I type 4.341111111111, It should get the value 4.35.
If I type 9.132222, It should be 9.14 not 9.13.

Expand|Select|Wrap|Line Numbers
  1. MsgBox(Math.Round(Val(TextBox1.Text), 2))
  2.  
  3. ' This is retrieving min value. Please help me to solve  this issue..
  4. All Codings are with Vb 2008
  5.  

Thank You,
Regards,
Supun Silva
Oct 29 '09 #1

✓ answered by Plater

Math.Ceiling() always rounds up.
14.9 or 14.1 will always be 15.
It might work in decimal form as well with an overload
OR combine with the multiply by 10 or 100 (experimenting is good)

9 4005
tlhintoq
3,525 Expert 2GB
"rounding" is always done as 5 and higher round up, 4 and lower round down.
So the round function you are using is working as it was meant to.

You will probably have to write your own function for this uncommon need.
Oct 29 '09 #2
supun24
11
Do you have any idea for this.. Please help me??

Thank You,
Supun Silva
Oct 29 '09 #3
tlhintoq
3,525 Expert 2GB
If I type 4.341111111111, It should get the value 4.35.
Multiply the float by 100 that will get you 434.1111111111
Make an int of that number getting you 434 since it will drop the decimal points
If the int is greater than the float then add 1 to the float getting you 435.1111111
Make an int of that getting you 435
Divide that by 100 getting you 4.35
Oct 29 '09 #4
Plater
7,872 Expert 4TB
Math.Ceiling() always rounds up.
14.9 or 14.1 will always be 15.
It might work in decimal form as well with an overload
OR combine with the multiply by 10 or 100 (experimenting is good)
Oct 29 '09 #5
tlhintoq
3,525 Expert 2GB
@Plater
Way cool. I love learning new things. There are just so many pre-existing functions that it is impossible to know them all.

Funny that they didn't use a name that was a little more intuitive:
Round( )
RoundUp( )
RoundDown( )

This would have also caused all three methods to appear next to each other in the namespace and in Intellisearch, steering people toward them even if they didn't know about them.

Or an override
Round(float)
Round(float, Enum.UpDown)

This is an example of something I would add to my own namespace with the other method calls to make sense to me.

Expand|Select|Wrap|Line Numbers
  1. public static int RoundUp(float Value)
  2. {
  3.    return Math.Ceiling(Value);
  4. }
Oct 29 '09 #6
supun24
11
Hi.. Thanks for your reply. Please be kindly send me the RoundUp code for VB 2008. not for C++. Please send me full cording. I couldn't understand above coding..

Regards,
Supun Silva
Oct 30 '09 #7
tlhintoq
3,525 Expert 2GB
@supun24
Plater already told you how to do this:
Math.Ceiling() always rounds up.
14.9 or 14.1 will always be 15.
It might work in decimal form as well with an overload
OR combine with the multiply by 10 or 100 (experimenting is good)
Where you are currently using Math.Round just replace with Math.Ceiling
Oct 30 '09 #8
supun24
11
No.. it is receiving without decimal places. I need number with 2 decimal places.
Ex:
If I have 14.1423242424242 --- It should be 14.15.

Hope you understand.
Regards,
Supun Silva
Oct 31 '09 #9
tlhintoq
3,525 Expert 2GB
Hmmmm.... Could there be an answer somewhere in all of this if one were to combine several pieces of advice?

Multiply by 100
Math.Ceiling
Divide by 100
Oct 31 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
7
by: bravesplace | last post by:
Hello, I am using the folling funtion to round a number to a single digit on my form: function round1(num) { return Math.round(num*1)/1 }
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
1
by: pmactdot | last post by:
Hey, Just started learning JS and really stuck on rounding to 2 decimals in the below ShowVal()? Have been playing around with *100/100, but no luck. function ShowVal() { var...
1
by: pmactdot | last post by:
Hi, I'm trying to get the below ShowVal() case study to dispaly/return a value to 2 decimals. Where/how would I use toFixed(2) instead or Math.round? function ShowVal() { var...
9
by: DaiOz | last post by:
Hi guys im doing a course which includes some JavaScript and I need help with the following question please, The code I have so far is below but I don't think its right please help as I need...
1
by: RiK ooo | last post by:
Hi, i'm currently working on C# project and I want to make use of the Math.Round() function to display only the first to digits of a float value. Unfortunately this doesn't seem to be working for me....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.