「Java」int型からdouble型に変換するサンプル

環境
Eclipe 2019
Java 8

書式
double 変数A = 値
int 変数B = (int)変数A

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.Test;
public class IntoDoubleDemo {
public static void main(String[] args) {
int cftA = 123;
// int型からdouble型に変換
double resA = cftA;
System.out.println(resA);
double cftC = 456.78;
// double型からint型に変換
int resB = (int) cftC;
System.out.println(resB);
}
}
package com.arkgame.Test; public class IntoDoubleDemo { public static void main(String[] args) { int cftA = 123; // int型からdouble型に変換 double resA = cftA; System.out.println(resA); double cftC = 456.78; // double型からint型に変換 int resB = (int) cftC; System.out.println(resB); } }
package com.arkgame.Test;

public class IntoDoubleDemo {

      public static void main(String[] args) {
            int cftA = 123;
            // int型からdouble型に変換
            double resA = cftA;
            System.out.println(resA);

            double cftC = 456.78;
            // double型からint型に変換
            int resB = (int) cftC;
            System.out.println(resB);
            
      }

}

実行結果
123.0
456

Java

Posted by arkgame