精确到小数的随机数 + 类型互转+控制精度


//------------------
double min = 0.501;//最小值
double max = 2;//总和
int scl = 3;//小数最大位数
int pow = (int) Math.pow(10, scl);//指定小数位
double one = Math.floor((Math.random() * (max - min) + min) * pow) / pow;
//-----------------------

 

String——> int      int a = Integer.parseInt(str);

int——> String     a+" ";

String ——> Double    Double.parseDouble(Str)   {D大写!!!!}

//--------------------------

String.format("%.2f",data)                        { 小数点后两位  }

 

posted @ 2019-01-10 09:46  努力化猿的鼠  阅读(349)  评论(0编辑  收藏  举报