By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,996 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,996 IT Pros & Developers. It's quick & easy.

how to trancate

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.