I want to round my decimal value, e.g. 2.2222 to 2.23. When I use the round,
decimal a = Math.Round((decimal)2.222, 2);
When I use the ceiling, it calls 3
decimal c = Math.Ceiling((decimal)2.22);
How can I get 2.2222 to 2.23?
I solved my problem.
string n = "2.2222"; string[] s = n.Split('.'); if (s[1].Count() >= 3) { List<char> z = s[1].ToString().Take(2).ToList(); int c=Convert.ToInt32(z[0].ToString() + z[1].ToString()) + 1; // int b = Convert.ToInt32(s[1].ElementAt(0).ToString() + s[1].ElementAt(1).ToString()) + 1; string output= s[0] + "." + c.ToString(); }
any number can now be added, it will take 2 decimal values ββand add 1.Thanks.
public static decimal CeilingAfterPoint(this decimal number, int digitsAfterPoint) { return Math.Ceiling(number * (decimal)Math.Pow(10, digitsAfterPoint)) / (decimal)Math.Pow(10, digitsAfterPoint); }
decimal c = Math.Ceiling((decimal)2.2222*100)/100;
but that is stupid.
try something like
decimal c = Math.Ceiling((decimal)2.222*100)/100;
but it fails if your value is 2.22
2.22
Source: https://habr.com/ru/post/1443638/More articles:jQuery does not work with Rails 3.2.8 - jquerySettings / configuration for the Google Closure compiler? - Play framework 2.0.4 - playframework-2.0Access to a JSF session limited by a bean from a servlet that is called by an applet built into the JSF webapp - javaToo many open files open and close when starting an infinite socket - cCreating a Java timer and TimerTask? - javaUpdating JTextField from another thread in Java - javaBidirectional JavaFX 2.2 communication in javascript and webview - javascriptCan I create multiple instances of the same component using a loop? - vhdlAndroid Phonegap 2.1> 2.2 Update Error - javaString size and font change in string.xml - androidAll Articles