计算中的小数点为。要么 , [英] Decimal point in calculations as . or ,

查看:89
本文介绍了计算中的小数点为。要么 ,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用十进制数字输入数字,则十进制根据国家和地区格式而变化。

可以作为一个点。或者作为逗号,

我无法控制使用该应用程序的设备。

如果区域格式使用逗号,则计算出错。输入5,6与仅输入5次和56次相同是相同的。

即使我以编程方式允许两者,也是如此。并且,作为TextField中的输入。

如何在不使用数字和标点符号的情况下解决这个问题,并且可能还必须提供说明以避免使用逗号输入,

它只是我需要的数字和小数的输入,小数点是更好。

解决方案

一种方法可以检查如果textField包含,。



如果包含,请将其替换为。并且执行所有算术运算。



无论如何,你将把所有textFields和textViews作为NSString对象读取,你可以根据需要操纵输入值并对其进行转换。 / p>

同时显示结果时替换。使用,以便用户根据区域格式感到舒适。


If I use decimal pad for input of numbers the decimal changes depending of country and region format.
May be as a point "." or as a comma ","
And I do not have control over at which device the app is used.
If the region format uses a comma the calculation gets wrong. Putting in 5,6 is the the same as putting in only 5 some times and as 56 same times.
And that is even if I programmatically allow both . and , as input in a TextField.
How do I come around this without using the numbers an punctation pad and probably also have to give instructions to avoid input with comma ","
It is only input for numbers and decimal I need and the decimal pad is so much nicer.

解决方案

One way could be to check if the textField contains a ",".

If it contains, replace it with "." and do all arithmetic operations.

As anyways you will be reading all textFields and textViews as NSString object, you can manipulate the input value and transform it according to your need.

Also while showing the result replace "." with "," so that user feel comfortable according to there regional formats.

这篇关于计算中的小数点为。要么 ,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆