473,385 Members | 1,588 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,385 software developers and data experts.

Round up

How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan
Nov 15 '05 #1
9 32606
add 0.5 and truncate?

Ruslan wrote:
How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan


Nov 15 '05 #2
add 0.5 and truncate?

Ruslan wrote:
How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan


Nov 15 '05 #3
"Ruslan" <ru*********@hotmail.com> wrote:
How can I round up a float number?
For example:
If I have a number 3.6 I want to obtain 4 and
If I have a number 3.1 also to obtain 4


(int) (n + 1)

....or use Math.Ceiling.

P.

--
www.CL4.org
Nov 15 '05 #4
"Ruslan" <ru*********@hotmail.com> wrote:
How can I round up a float number?
For example:
If I have a number 3.6 I want to obtain 4 and
If I have a number 3.1 also to obtain 4


(int) (n + 1)

....or use Math.Ceiling.

P.

--
www.CL4.org
Nov 15 '05 #5
"Paul E Collins" <fi******************@CL4.org> wrote:
How can I round up a float number?
[...]
(int) (n + 1)


Oops. That won't work if n has no fractional part.
...or use Math.Ceiling.


P.

--
www.CL4.org
Nov 15 '05 #6
"Paul E Collins" <fi******************@CL4.org> wrote:
How can I round up a float number?
[...]
(int) (n + 1)


Oops. That won't work if n has no fractional part.
...or use Math.Ceiling.


P.

--
www.CL4.org
Nov 15 '05 #7
Ruslan,
Have you tried System.Math.Ceiling? Which returns the smallest whole number
greater than or equal to the specified number.

Note for negative numbers it will return numbers closer to zero.

Ceiling(-3.6) will return -3.

The function System.Match.Floor will return the smallest whole number less
than or equal to the specified number.

Hope this helps
Jay

"Ruslan" <ru*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan

Nov 15 '05 #8
Ruslan,
Have you tried System.Math.Ceiling? Which returns the smallest whole number
greater than or equal to the specified number.

Note for negative numbers it will return numbers closer to zero.

Ceiling(-3.6) will return -3.

The function System.Match.Floor will return the smallest whole number less
than or equal to the specified number.

Hope this helps
Jay

"Ruslan" <ru*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan

Nov 15 '05 #9
Thanks, Jay

It helped me.

Ruslan

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:#Q**************@TK2MSFTNGP12.phx.gbl...
Ruslan,
Have you tried System.Math.Ceiling? Which returns the smallest whole number greater than or equal to the specified number.

Note for negative numbers it will return numbers closer to zero.

Ceiling(-3.6) will return -3.

The function System.Match.Floor will return the smallest whole number less
than or equal to the specified number.

Hope this helps
Jay

"Ruslan" <ru*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
How can I round up a float number?

For example:

If I have a number 3.6 I want to obtain 4 and

If I have a number 3.1 also to obtain 4

Thanks a lot.

Ruslan


Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matias Silva | last post by:
Can anybody tell me why I am getting rounding errors using the ROUND function. 3.7125 rounds to 3.70 when I use the following: TRUNCATE(ROUND(units_pay_amount * fees_amount, 2),2))) The correct...
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
17
by: nomenklatura | last post by:
Hi, System.Math.Round function is confused me. for example i want to round 3.245 in with decimal symbol Result should be = 3.25 When i try to this in vb: A = 3.245 X = Round(A, 2) then...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
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)...
7
by: kkmigas | last post by:
Can some one explain if this can be fixed using php.ini settings ? echo "round 20.545 -".round(20.545,2)."<br>"; echo "round 20.555 -".round(20.555,2)."<br>"; echo "number_format 20.545...
3
by: Krishna.K.1900 | last post by:
Does round() always perfectly return the output expected or are there some artifacts which don't allow perfect functionality Using python 2.5: 12.23 12.234 12.199999999999999 but was...
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 !!!!
9
by: josh logan | last post by:
Hello, I need a round function that _always_ rounds to the higher integer if the argument is equidistant between two integers. In Python 3.0, this is not the advertised behavior of the built-in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.