将BigDecimal转换为scale = 2的相反值

时间:2018-04-26 20:08:35

标签: java bigdecimal

我有一个bigdecimal,但我想转换为setScale = 2的反面。

  

1 - > 0.01

     

123 - > 1.23

     

5555555 - > 55555.55

我该怎么做?

1 个答案:

答案 0 :(得分:1)

这应该有效:

示例:

@SwaggerDefinition(
        info = @Info(
                description = "My API",
                version = "V1.2.3",
                title = "The only API you'll ever need to learn about me",
                termsOfService = "share and care",
                contact = @Contact(name = "Sponge-Bob", email = "sponge-bob@swagger.io", url = "http://swagger.io"),
                license = @License(name = "Apache 2.0", url = "http://www.apache.org"),

        consumes = {"application/json" },
        produces = {"application/json" },
        schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
        externalDocs = @ExternalDocs(value = "About me", url = "http://about.me/me")
)
public interface MyApiDefinition {}

输出:

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;

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

    Scanner in = new Scanner(System.in); 
    int   number= in.nextInt();
    BigDecimal bd = new BigDecimal(number); 
    BigDecimal rslt = bd.divide(BigDecimal.valueOf(100));
    System.out.println(rslt );


}

}