小编use*_*675的帖子

如何获取Java中小数点后的部分?

我有一个double变量d = 1.15.

我想要小数点后的数字,即"15".

在Java中实现这一目标的最佳方法是什么?

我试过这样的:

Double d = 1.15;
String str = d.toString();
int len = str.substring(str.indexOf(".")).length() - 1;
int i= (int) (d * (long)Math.pow(10,len) % (long)Math.pow(10,len));
Run Code Online (Sandbox Code Playgroud)

但我没有得到正确答案,因为当我转换d.toString()答案时14.999999999999986.

java

11
推荐指数
5
解决办法
4万
查看次数

处理智能方式的条件

if (lineStyle == 5 || lineStyle == 21 || lineStyle == 82 || lineStyle == 83 || lineStyle == 3) {
    lineStyleString = "DOUBLE";
} else if (lineStyle == 6 || lineStyle == 35 || lineStyle == 39 || lineStyle == 30) {
    lineStyleString = "DOTTED" ;
} else if (lineStyle == 26 || lineStyle == 27  || lineStyle == 28  || lineStyle == 29 || lineStyle == 1) {
    lineStyleString = "SOLID";
} else if(lineStyle == -1) {
    lineStyleString …
Run Code Online (Sandbox Code Playgroud)

java

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

Java:lastindexOf的正则表达式

我的示例代码:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

    /**
     * @param args
     */

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String str[] = {"A","B","C"};
        String s = "TEST FOR A STRING CONSTANT B. END.";
        int retIndex = -1;

        for (int i = 0, len = str.length; i < len; i++){ 
            //length-1 is because, we should not check the empty space unicode(\u0021)

            int index = s.lastIndexOf(str[i]);
            if(index>retIndex){
                retIndex = index;
            }
        }
        System.out.println("RETINDEX"+retIndex);

        Pattern pattern = …
Run Code Online (Sandbox Code Playgroud)

java regex

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

标签 统计

java ×3

regex ×1