从包含任意格式数字的字符串中解析 BigDecimal
我们从格式化为文本的 XLS 单元格中读取数据。
该单元格希望包含一个数字,输出将是 BigDecimal(因为任意精度)。
问题是,单元格格式也是任意的,这意味着它可能包含以下数字:
- 带有货币符号($1000)
- 前导和尾随空格,或数字之间的空格(例如 1 000 )
- 数字分组符号(例如 1,000.0)
- 当然 、负数
- 'o' 和 'O' 作为零(例如 1,ooo.oo),
- 其他我想不出
这主要是因为最后一点,我正在寻找一个标准库可以做到这一切,并且是可配置的,经过良好测试等。
我首先查看了 Apache,什么也没发现,但我可能是盲目的......也许这对其他人来说是一个微不足道的答案......
更新:问题的领域是财务应用程序。实际上,我期待一个库,其中域可以是输入参数 - 金融、科学等。也许更具体:带有货币符号的金融?有股票代码吗?距离和其他测量单位?我不敢相信我是第一个想到这样的事情的人......
We read data from XLS cells formatted as text.
The cell hopefully contains a number, output will be a BigDecimal (because of arbitrary precision).
Problem is, the cell format is also arbitrary, which means it may contain numbers like:
- with currency symbols ($1000)
- leading and trailing whitespaces, or whitespaces in between digits (eg. 1 000 )
- digit grouping symbols (eg. 1,000.0)
- of course, negative numbers
- 'o's and 'O's as zeros (eg. 1,ooo.oo)
- others I can't think of
It's mostly because of this last point that I'm looking for a standard library that can do all this, and which is configurable, well tested etc.
I looked at Apache first, found nothing but I might be blind... perhaps it's a trivial answer for someone else...
UPDATE: the domain of the question is financial applications. Actually I'm expecting a library where the domain could be an input parameter - financial, scientific, etc. Maybe even more specific: financial with currency symbols? With stock symbols? With distances and other measurement units? I can't believe I'm the first person to think of something like this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道任何库,但你可以尝试:
这应该可以解决 99条目的百分比...
I don't know any library, but you can try that:
That should solve 99% of the entrys...
购买一堆照片,甚至更好的包含合法成人内容的视频。使用这些资源创建一个网站,但使用验证码限制访问,验证码将显示未解析的数字格式。使用已知的数字格式创建一组数字解码器,并创建一个算法,该算法将根据用户解决的验证码添加新的解码器。
Buy bunch photos or even better videos with legal adult content. Create a web site with these resources but limit the access with captcha which will be displaying unsolved number formats. Create a set of number decoders out of known number formats and create an algorithm which will add new ones based on user solved captchas.
我想这就是我一直在寻找的:
http://site.icu-project.org/
非常强大的库,虽然目前还不清楚它是否只能格式化或者所有格式化的东西也可以解析回来。
I think this is what I've been looking for:
http://site.icu-project.org/
Very powerful library, although at the moment it's not clear whether it can only format or all the formatted stuff can be parsed back as well.