From 4ee77a295442b3dad021f671c309eb1fb33bf01a Mon Sep 17 00:00:00 2001 From: wook Date: Tue, 25 Apr 2017 19:06:20 +0900 Subject: [PATCH] RoundEx and CeilingEx --- MathEx.sln | 6 + MathEx/Class1.cs | 12 -- MathEx/MathEx.cs | 55 +++++++ MathEx/MathEx.csproj | 27 ++-- MathExExample/App.config | 6 + MathExExample/Form1.Designer.cs | 153 ++++++++++++++++++ MathExExample/Form1.cs | 32 ++++ MathExExample/Form1.resx | 120 ++++++++++++++ MathExExample/MathExExample.csproj | 88 ++++++++++ MathExExample/Program.cs | 22 +++ MathExExample/Properties/AssemblyInfo.cs | 36 +++++ .../Properties/Resources.Designer.cs | 71 ++++++++ MathExExample/Properties/Resources.resx | 117 ++++++++++++++ MathExExample/Properties/Settings.Designer.cs | 30 ++++ MathExExample/Properties/Settings.settings | 7 + 15 files changed, 752 insertions(+), 30 deletions(-) delete mode 100644 MathEx/Class1.cs create mode 100644 MathEx/MathEx.cs create mode 100644 MathExExample/App.config create mode 100644 MathExExample/Form1.Designer.cs create mode 100644 MathExExample/Form1.cs create mode 100644 MathExExample/Form1.resx create mode 100644 MathExExample/MathExExample.csproj create mode 100644 MathExExample/Program.cs create mode 100644 MathExExample/Properties/AssemblyInfo.cs create mode 100644 MathExExample/Properties/Resources.Designer.cs create mode 100644 MathExExample/Properties/Resources.resx create mode 100644 MathExExample/Properties/Settings.Designer.cs create mode 100644 MathExExample/Properties/Settings.settings diff --git a/MathEx.sln b/MathEx.sln index e753972..07f213b 100644 --- a/MathEx.sln +++ b/MathEx.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathEx", "MathEx\MathEx.csproj", "{FE22BB43-5C91-451E-8E5C-08D02AA4B080}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathExExample", "MathExExample\MathExExample.csproj", "{14B091F4-F22E-43EE-B6AE-1453DB9AE246}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {FE22BB43-5C91-451E-8E5C-08D02AA4B080}.Debug|Any CPU.Build.0 = Debug|Any CPU {FE22BB43-5C91-451E-8E5C-08D02AA4B080}.Release|Any CPU.ActiveCfg = Release|Any CPU {FE22BB43-5C91-451E-8E5C-08D02AA4B080}.Release|Any CPU.Build.0 = Release|Any CPU + {14B091F4-F22E-43EE-B6AE-1453DB9AE246}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14B091F4-F22E-43EE-B6AE-1453DB9AE246}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14B091F4-F22E-43EE-B6AE-1453DB9AE246}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14B091F4-F22E-43EE-B6AE-1453DB9AE246}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MathEx/Class1.cs b/MathEx/Class1.cs deleted file mode 100644 index 849a9a6..0000000 --- a/MathEx/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MathEx -{ - public class Class1 - { - } -} diff --git a/MathEx/MathEx.cs b/MathEx/MathEx.cs new file mode 100644 index 0000000..1ab06ab --- /dev/null +++ b/MathEx/MathEx.cs @@ -0,0 +1,55 @@ +using System; + +namespace MathExtention +{ + public static class MathEx + { + /// + /// Round Number by Custom Interval + /// + /// Primitive + /// Interval + /// + public static double RoundEx(double d0, double di) + { + di = 1 / di; + return Math.Round(d0 * di) / di; + } + + /// + /// Round Number by Custom Interval + /// + /// Primitive + /// Interval + /// + public static decimal RoundEx(decimal d0, decimal di) + { + di = 1 / di; + return Math.Round(d0 * di) / di; + } + + /// + /// Ceiling Number by Custom Interval + /// + /// Primitive + /// Interval + /// + public static double CeilingEx(double d0, double di) + { + di = 1 / di; + return (d0 > 0 ? Math.Ceiling(d0 * di) : Math.Floor(d0 * di)) / di; + } + + /// + /// Ceiling Number by Custom Interval + /// + /// Primitive + /// Interval + /// + public static decimal CeilingEx(decimal d0, decimal di) + { + di = 1 / di; + return (d0 > 0 ? Math.Ceiling(d0 * di) : Math.Floor(d0 * di)) / di; + } + } +} diff --git a/MathEx/MathEx.csproj b/MathEx/MathEx.csproj index 15b7c3f..09f3651 100644 --- a/MathEx/MathEx.csproj +++ b/MathEx/MathEx.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - fe22bb43-5c91-451e-8e5c-08d02aa4b080 + {FE22BB43-5C91-451E-8E5C-08D02AA4B080} Library Properties MathEx @@ -30,24 +30,15 @@ 4 - - - - - - - - - - - - - - + + + + + - + - + \ No newline at end of file diff --git a/MathExExample/App.config b/MathExExample/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/MathExExample/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MathExExample/Form1.Designer.cs b/MathExExample/Form1.Designer.cs new file mode 100644 index 0000000..198d580 --- /dev/null +++ b/MathExExample/Form1.Designer.cs @@ -0,0 +1,153 @@ +namespace MathExExample +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.numPrimitive = new System.Windows.Forms.NumericUpDown(); + this.numInterval = new System.Windows.Forms.NumericUpDown(); + this.lblInterval = new System.Windows.Forms.Label(); + this.lblResult = new System.Windows.Forms.Label(); + this.numResult = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numPrimitive)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numInterval)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numResult)).BeginInit(); + this.SuspendLayout(); + // + // numPrimitive + // + this.numPrimitive.DecimalPlaces = 2; + this.numPrimitive.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.numPrimitive.Increment = new decimal(new int[] { + 5, + 0, + 0, + 131072}); + this.numPrimitive.Location = new System.Drawing.Point(91, 13); + this.numPrimitive.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numPrimitive.Name = "numPrimitive"; + this.numPrimitive.Size = new System.Drawing.Size(90, 29); + this.numPrimitive.TabIndex = 1; + this.numPrimitive.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.numPrimitive.ValueChanged += new System.EventHandler(this.num_ValueChanged); + // + // numInterval + // + this.numInterval.DecimalPlaces = 2; + this.numInterval.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.numInterval.Increment = new decimal(new int[] { + 5, + 0, + 0, + 131072}); + this.numInterval.Location = new System.Drawing.Point(90, 48); + this.numInterval.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numInterval.Name = "numInterval"; + this.numInterval.Size = new System.Drawing.Size(90, 29); + this.numInterval.TabIndex = 2; + this.numInterval.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.numInterval.ValueChanged += new System.EventHandler(this.num_ValueChanged); + // + // lblInterval + // + this.lblInterval.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.lblInterval.Location = new System.Drawing.Point(12, 48); + this.lblInterval.Name = "lblInterval"; + this.lblInterval.Size = new System.Drawing.Size(72, 29); + this.lblInterval.TabIndex = 1; + this.lblInterval.Text = "Interval"; + this.lblInterval.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // lblResult + // + this.lblResult.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.lblResult.Location = new System.Drawing.Point(12, 80); + this.lblResult.Name = "lblResult"; + this.lblResult.Size = new System.Drawing.Size(72, 29); + this.lblResult.TabIndex = 1; + this.lblResult.Text = "Result"; + this.lblResult.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // numResult + // + this.numResult.DecimalPlaces = 2; + this.numResult.Enabled = false; + this.numResult.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.numResult.Increment = new decimal(new int[] { + 5, + 0, + 0, + 131072}); + this.numResult.Location = new System.Drawing.Point(90, 83); + this.numResult.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numResult.Name = "numResult"; + this.numResult.ReadOnly = true; + this.numResult.Size = new System.Drawing.Size(90, 29); + this.numResult.TabIndex = 0; + this.numResult.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(194, 128); + this.Controls.Add(this.lblResult); + this.Controls.Add(this.lblInterval); + this.Controls.Add(this.numResult); + this.Controls.Add(this.numInterval); + this.Controls.Add(this.numPrimitive); + this.Name = "Form1"; + this.Text = "MathEx"; + ((System.ComponentModel.ISupportInitialize)(this.numPrimitive)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numInterval)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numResult)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.NumericUpDown numPrimitive; + private System.Windows.Forms.NumericUpDown numInterval; + private System.Windows.Forms.Label lblInterval; + private System.Windows.Forms.Label lblResult; + private System.Windows.Forms.NumericUpDown numResult; + } +} + diff --git a/MathExExample/Form1.cs b/MathExExample/Form1.cs new file mode 100644 index 0000000..49567a7 --- /dev/null +++ b/MathExExample/Form1.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using MathExtention; + +namespace MathExExample +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + this.numPrimitive.Value = 285.30m; + this.numInterval.Value = 2.5m; + } + + private void num_ValueChanged(object sender, EventArgs e) + { + if (this.numInterval.Value != 0) + { + this.numResult.Value = MathEx.RoundEx(this.numPrimitive.Value, this.numInterval.Value); + this.numPrimitive.Focus(); + } + } + } +} diff --git a/MathExExample/Form1.resx b/MathExExample/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MathExExample/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MathExExample/MathExExample.csproj b/MathExExample/MathExExample.csproj new file mode 100644 index 0000000..976a356 --- /dev/null +++ b/MathExExample/MathExExample.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {14B091F4-F22E-43EE-B6AE-1453DB9AE246} + WinExe + MathExExample + MathExExample + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {fe22bb43-5c91-451e-8e5c-08d02aa4b080} + MathEx + + + + \ No newline at end of file diff --git a/MathExExample/Program.cs b/MathExExample/Program.cs new file mode 100644 index 0000000..7d487bf --- /dev/null +++ b/MathExExample/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MathExExample +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/MathExExample/Properties/AssemblyInfo.cs b/MathExExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5638517 --- /dev/null +++ b/MathExExample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MathExExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MathExExample")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("14b091f4-f22e-43ee-b6ae-1453db9ae246")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MathExExample/Properties/Resources.Designer.cs b/MathExExample/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9531b05 --- /dev/null +++ b/MathExExample/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathExExample.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathExExample.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MathExExample/Properties/Resources.resx b/MathExExample/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MathExExample/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MathExExample/Properties/Settings.Designer.cs b/MathExExample/Properties/Settings.Designer.cs new file mode 100644 index 0000000..7a48ae3 --- /dev/null +++ b/MathExExample/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathExExample.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MathExExample/Properties/Settings.settings b/MathExExample/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MathExExample/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + +