
Recent Posts

Recent Comments
 Why you should study algorithms (plus a free book drawing)  C# HelperC# Helper on Book Drawing: The Modern C# Challenge
 charles on Make a 3D globe in WPF and C#
 RodStephens on Give an image a transparent background in C#
 kaliprasad m on Give an image a transparent background in C#
 RodStephens on Graph points in WPF and C#
Archives
 January 2019
 December 2018
 November 2018
 October 2018
 September 2018
 August 2018
 July 2018
 June 2018
 May 2018
 April 2018
 March 2018
 February 2018
 January 2018
 December 2017
 November 2017
 October 2017
 September 2017
 August 2017
 July 2017
 June 2017
 May 2017
 April 2017
 March 2017
 February 2017
 January 2017
 December 2016
 November 2016
 October 2016
 September 2016
 August 2016
 July 2016
 June 2016
 May 2016
 April 2016
 March 2016
 February 2016
 January 2016
 December 2015
 November 2015
 October 2015
 September 2015
 August 2015
 July 2015
 June 2015
 May 2015
 April 2015
 March 2015
 February 2015
 January 2015
 December 2014
 November 2014
 October 2014
 September 2014
 August 2014
 July 2014
 June 2014
 May 2014
 February 2014
 January 2014
 December 2013
 October 2013
 August 2013
 June 2013
 December 2012
 September 2012
 July 2012
 June 2012
 November 2011
 May 2011
 April 2011
 February 2011
 December 2010
Categories
 .NET
 3D
 3D graphics
 ADO.NET
 algorithms
 animation
 API
 arrays
 attributes
 audio
 books
 C#
 C# programming
 calculations
 challenges
 classes
 clipboard
 coding
 combinatorics
 console
 controls
 cryptography
 curve fitting
 database
 debugging
 dialogs
 directories
 Drag and Drop
 drawing
 drawings
 enums
 Event
 events
 example program
 Excel
 extension methods
 extensions
 files
 finance
 fonts
 formatting
 forms
 fractals
 ftp
 games
 GDI+
 generic
 geometry
 globalization
 graphics
 html
 IDE
 image processing
 inheritance
 interfaces
 internationalization
 internet
 interoperability
 LINQ
 lists
 localization
 mathematics
 memory
 menus
 MessageBox
 methods
 miscellany
 multimedia
 network
 Office
 OOP
 operators
 parsing
 performance
 phone
 PowerPoint
 printers
 printing
 productivity
 programs
 puzzles
 recursion
 reflection
 registry
 regular expressions
 serialization
 settings
 SQL
 stories
 strings
 syntax
 system
 threading
 tips
 tools
 transformations
 Uncategorized
 user interface
 variables
 VBA
 web
 Windows Forms programming
 WMI
 Word
 wpf
 XAML
 XML
Meta
Tag Archives: calculations
Control a loop that uses floatingpoint values in C#
Sometimes you might need to use a floatingpoint variable that loop over a range of values. For example, you might want a value to step through the values 0.0 through 1.0 in increments of 0.1. The sequence of numbers would … Continue reading
Posted in calculations, mathematics, variables
Tagged C#, C# programming, calculations, double, example, example program, float, floatingpoint, for loop, loop, mathematics, rounding, rounding errors, variables, Windows Forms programming
Leave a comment
Compare floatingpoint values safely in C#
The computer stores values, including floatingpoint values, in binary using 0s and 1s. That means it cannot store all possible decimal values exactly. Sometimes when you multiply or divide two floatingpoint values, the computer is unable to store the result … Continue reading
Calculate credit payments in WPF and C#
This is a WPF version of the example Calculate credit payments in C#. The calculations are the same. Unfortunately building and using the user interface is much harder in WPF, particularly working with the ListView control. (The unofficial WPF slogan: … Continue reading
Use the BigInteger structure in C#
The long data type can hold values between roughly 9.2 x 1018 and 9.2 x 1018, but sometimes even that range isn’t big enough. The .NET Framework 4.0 (C# 4.0 or Visual Studio 2010) introduced the BigInteger structure to represent … Continue reading
Posted in mathematics
Tagged BigInteger, C#, C# programming, calculate, calculations, example, example program, mathematics, Windows Forms programming
2 Comments
Use “banker’s rounding” and “normal rounding” in C#
By default the Math.Round method uses “banker’s rounding.” In banker’s rounding a number with a final digit of 5 is rounded to the nearest even number rather than to the next larger number as you might expect. The idea is … Continue reading
Define and use bit masks in C#
The example Understand bit masks in C# explains how to use bit masks. To define a bit mask, simply create an enum and give it the Flags attribute as in the following code. [Flags] private enum BitmaskEnum { Value1 = … Continue reading
Understand bit masks in C#
Some values, including some properties defined by the .NET Framework, are bit masks. That means each bit in a value means something. For example, the AnchorStyles enumeration that determines how controls are anchored in their parents defines four values: Top, … Continue reading
Use bit operations in C#
C# defines several operators that perform bit operations. As you may be able to guess from the names, these operators manipulate the bits in an integer value. They operate on the value’s bits separately so they are sometimes called “bitwise … Continue reading
Posted in calculations, mathematics, variables
Tagged and, bit operations, bit shift, bitwise operations, C#, C# programming, calculations, example, example program, mathematics, or, variables, Windows Forms programming, xor
Leave a comment
Compare speeds of arithmetic operations in C#
This example compares the speeds of arithmetic operations with different data types. There’s a big difference between the speeds of operations using the decimal data type and the other types, so performing a loop a certain number of time is … Continue reading
Posted in algorithms, calculations, mathematics
Tagged algorithms, arithmetic, arithmetic operations, byte, C#, C# programming, calculations, data types, decimal, double, example, example program, float, integer, long, mathematics, Windows Forms programming
Leave a comment
Calculate credit payments in C#
For each month the program: Calculates the payment first. This is either a percent of the balance or the minimum amount, whichever is greater. Calculates interest after the payment is calculated but before it is subtracted from the balance. Adds … Continue reading
Posted in algorithms, calculations, finance, mathematics
Tagged algorithms, C#, C# programming, calculations, credit, credit card, credit payments, example, example program, finance, interest, mathematics, payments, Windows Forms programming
7 Comments