相关疑难解决方法(0)

浮点数学是否破碎?

请考虑以下代码:

0.1 + 0.2 == 0.3  ->  false
Run Code Online (Sandbox Code Playgroud)
0.1 + 0.2         ->  0.30000000000000004
Run Code Online (Sandbox Code Playgroud)

为什么会出现这些不准确之处?

language-agnostic math floating-point floating-accuracy

2798
推荐指数
28
解决办法
28万
查看次数

为什么不使用Double或Float来表示货币?

我总是被告知永远不要代表钱doublefloat类型,这次我向你提出问题:为什么?

我确信有一个很好的理由,我根本不知道它是什么.

floating-point currency

887
推荐指数
11
解决办法
27万
查看次数

用文字打印数字

我正在尝试使用单词打印三位数的代码.但如果右边的前两位数介于11和19之间(包括两者),则无效.

有帮助吗?

package com;

import java.util.Stack;

public class TestMain {
public static void main(String[] args) {

Integer i=512;
int temp =i;int pos=1;
Stack<String> stack=new Stack<String>();
while(temp>0){

    int rem=temp%10;
    temp=temp/10;
    if(rem!=0){stack.push(getString(rem, pos));}
    pos*=10;
}
do{
    System.out.print(stack.pop()+" ");
}while(!stack.isEmpty());



}
static String getString(int i,int position){
    String str=null;

    if(position==10){
        i*=position;
    }

    switch(i){
    case 1:
        str= "One";break;

    case 2:
        str= "two";break;
    case 3:
        str= "three";break;
    case 4:
        str= "four";break;
    case 5:
        str= "five";break;
    case 6:
        str= "six";break;
    case 7:
        str= "seven";break;
    case 8:
        str= …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1万
查看次数