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

how to trancate

uto
i'd like to trancate like this.

1.555 => 1
2.6655 = > 2
0.901923 = > 0

and

1.56 => 1.5
1.34 => 1.3
1.99 => 1.9

how can i do this in c#
Apr 3 '06 #1
1 1947
uto,

It seems like you want a floor function. There is nothing like this in
..NET which can do this for you, but it is easy enough to program.

public static double Floor(double value)
{
// Just return the overload.
return Floor(value, 0);
}

public static double Floor(double value, int digits)
{
// Check here to see if digits is negative.

// Get the amount to subtract from value. Generally, if you are
rounding
// to 0 places, then you would subtract .5, and round normally. If to
// 1 place, then subtract .05, etc, etc.
int powerOfTen = Math.Pow(10, digits);

// Now subtract, and round.
return Math.Round(value - (.5 * powerOfTen), digits);
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"uto" <so**********@gmail.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
i'd like to trancate like this.

1.555 => 1
2.6655 = > 2
0.901923 = > 0

and

1.56 => 1.5
1.34 => 1.3
1.99 => 1.9

how can i do this in c#

Apr 3 '06 #2

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

Similar topics

10
by: Mavenos | last post by:
Hi Web Masters, Just wondering wether you can help us to come up with some tokenize script. My problem is wanted to display a LONG content into a short para (by giving minimum letter lenght)...
5
by: Frank Swarbrick | last post by:
Take the following table CREATE TABLE MGR_DEV1.ADDRESSES ( CUSTOMER_NBR DECIMAL (9, 0) NOT NULL , ADDR_KEY DECIMAL (3, 0) NOT NULL , STREET_ADDR_1 VARCHAR (40) NOT NULL , STREET_ADDR_2...
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
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: 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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.