「C#」小数値を含むかどうか判定するサンプル

書式
Floor(Double)
指定した倍精度浮動小数点数以下の数のうち、最大の整数値を返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Globalization;
namespace TestDemo
{
class Program
{
static void Main(string[] args)
{ 
//小数値を含む場合
bool resA = IsFunc(3.45);
Console.WriteLine(resA);
//小数値を含まない場合
bool resB = IsFunc(87.0);
Console.WriteLine(resB);
}
//小数値が存在するか判定関数
  public static bool IsFunc(double db)
{
return (db - Math.Floor(db) != 0);
}
}
}
using System; using System.Globalization; namespace TestDemo { class Program { static void Main(string[] args) {  //小数値を含む場合 bool resA = IsFunc(3.45); Console.WriteLine(resA); //小数値を含まない場合 bool resB = IsFunc(87.0); Console.WriteLine(resB); } //小数値が存在するか判定関数   public static bool IsFunc(double db) { return (db - Math.Floor(db) != 0); } } }
using System;

using System.Globalization;
namespace TestDemo
{
  class Program
  {
    static void Main(string[] args)
    {    
        //小数値を含む場合
          bool resA = IsFunc(3.45);
         Console.WriteLine(resA);
         
         //小数値を含まない場合
        bool resB = IsFunc(87.0);
        Console.WriteLine(resB);

    }
     //小数値が存在するか判定関数
     public static bool IsFunc(double db)
     {
         return (db - Math.Floor(db) != 0);
       }
    }
}

結果
True
False

C#

Posted by arkgame