`
sunxboy
  • 浏览: 2877980 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

how to parse a String to BigDecimal

 
阅读更多
private BigDecimal parsePrice(String price) {
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        //symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        String pattern = "#.##";
        DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
        decimalFormat.setParseBigDecimal(true);

        // parse the string
        BigDecimal bigDecimal = null;
        try {
            bigDecimal = (BigDecimal) decimalFormat.parse(price);
        }
        catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(bigDecimal);
        return bigDecimal;
    }

 

分享到:
评论

相关推荐

    解决dbf Failed to parse Number: For input string: "-.---"

    本文将深入探讨标题和描述中提到的问题:“解决dbf Failed to parse Number: For input string: "-.---""”,以及如何在不依赖特定jar包的情况下处理DBF文件。 首先,"Failed to parse Number: For input string: ...

    Jboss启动报Failed to parse WEB-INFweb.xml; - nested throwable错误

    Jboss启动报Failed to parse WEB-INF/web.xml; - nested throwable错误解决方案 在Jboss应用服务器中,启动报错Failed to parse WEB-INF/web.xml; - nested throwable是一种常见的错误,本文将对此错误进行深入分析...

    parse xml string from url to POJO

    在给定的场景中,"parse xml string from url to POJO"涉及到的主要知识点包括XML解析、网络请求以及数据绑定。以下是对这些关键点的详细说明: 1. **XML解析**: XML是一种结构化数据格式,广泛用于数据交换。在...

    Learning to Parse Natural Language with Maximum Entropy Models

    In practice, the running time of the parser on a test sentence is linear with respect to the sentence length. We also demonstrate that the parser can train from other domains without modification to ...

    How to Convert String Value to JSON Object.zip

    let jsonObject = JSON.parse(jsonString); console.log(jsonObject); // 输出: { name: 'John', age: 30, city: 'New York' } ``` 2. **JSON.stringify()**: 反之,如果你有一个JavaScript对象并且想将其转换为...

    convert string to integer

    在本篇文章中,我们将深入探讨如何在不同的编程语言中实现`convert string to integer`的功能,以帮助开发者更好地理解和应用这个概念。 首先,让我们以 Ruby 为例,这可能与提供的压缩包文件 `string_to_integer....

    QT CMake 3.3编译器

    QT CMake 3.3编译器 解决 使用Qt Creator 14.0.1 (Community) 创建项目时...报错的内容就是:error: The kit needs to define a CMake tool to parse this project. 译 错误:工具包需要定义一个CMake工具来解析这个项目

    Parse JSON in TSQL

    Is it possible to parse JSON in TSQL? I dont mean to create a JSON string, i mean to parse a json string passed in as a parameter.数据库parseJSON 转表

    TS Expert(To Parse DVB transport stream)

    (这个版本不需要License的版本... Be able to parse TS packets and PES packets  Be able to retrieve TS packets, sections and PES packets  With a powerful CRC calculation tool and a CSA cipher tool

    kotlin dlt library to parse autosar dlt files

    kotlin dlt library to parse autosar dlt files

    iOS Apprentice 4 StoreSearch v4.1

    parse JSON data, and how to download files such as images. You are going to build an app that lets you search the iTunes store. Of course, your iPhone already has apps for that (“App Store” and ...

    Foundations for Analytics with Python O-Reilly-2016-Clinton W. Brownley

    This is a reminder that you can parse text files with basic string oper‐ ations and another good example of how to use a nested dictionary to group or bin data into unique categories. Chapter 6, ...

    Practical Common LISP(Apress,2012)

    In other “practical” chapters, author Peter Seibel demonstrates how to build a simple but flexible in-memory database, how to parse binary files, and how to build a unit test framework in 26 lines ...

    iOS eCommerce App Development with Parse(Apress,2015).pdf

    iOS eCommerce App Development with Parse uses a real-world app example to teach you how to build a complete eCommerce iPhone app powered by Parse—the most popular and powerful Platform as a Service ...

    【数据挖掘重要笔记day31】详细完解决iris = sns.load_dataset(‘iris’)出来EmptyDataError: No columns to parse from file报错

    EmptyDataError: No columns to parse from file报错 原因和解决办法: 是因为你之前下载这个数据集的时候,中断了,已经产生了一个iris.csv的空文件在home家目录下面,你只需要去home家目录下面删除这个空文件既...

    Expert.Android

    How to use Parse cloud for Storage, Collaborative Social Apps, and Push notifications How to create Custom Views, Controls, and Layouts How to create 3D experience with OpenGL ES 2.0 How to achieve ...

    El表达式使用问题javax.el.ELException:Failed to parse the expression的解决方式

    然而,当出现`javax.el.ELException: Failed to parse the expression`错误时,这通常意味着EL表达式没有被正确解析,导致程序无法正常运行。该错误通常是由于违反了EL表达式的语法规则,或者尝试执行了不合法的操作...

    C# String 的各种转换

    string result = string.Format("{0:G}", a / b); // "11.464990318471337" ``` - **科学计数法 (E)**: ```csharp string result = string.Format("{0:E}", a / b); // "1.14649903184713E+01" ``` - **货币...

Global site tag (gtag.js) - Google Analytics