number-formatting

In Java, why does the decimal separator follow the Locale's language, not its country, and, more importantly, how does one override it?

自古美人都是妖i 提交于 2019-12-12 08:34:47
问题 I'm working on an international project and have observed that, in Java, the choice of the decimal separator is based on the Locale's language, not its country. For example: DecimalFormat currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("it","IT")); System.out.println(currencyFormatter.format(-123456.78)); currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("en","IT")); System.out.println(currencyFormatter.format(-123456.78)); produces the following

excel interop : NumberFormat #,##0.000 doesn't display the expected result

孤者浪人 提交于 2019-12-12 03:54:10
问题 I developed a C# utility class called ExcelGenerator that generate a List of objects to excel. I want to display double numbers in this format : 3 288,523. NumberFormat = "#,##0.000" doesn't display the expected result This is the method : public void FormatNombre(string frm) { _excel.Selection.NumberFormat = frm; } and this is the call : eg.FormatNombre("#,##0.000"); Number still displayed like this : 3288,522.542 回答1: You want to format 3288523.542 to 3 288,523? Try something like this: [

Format Doubles to String [duplicate]

狂风中的少年 提交于 2019-12-12 03:49:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to nicely format floating types to String? How can I list the number with up to two decimal places? I tried this method: http://developer.android.com/reference/java/text/NumberFormat.html but no luck. Below code. Maybe someone can help me. package karcio.fuel.economy; public class FuelEconomy extends Activity { private EditText editText1; private EditText editText2; private TextView textView4; private

How to convert price format to number only with php?

烈酒焚心 提交于 2019-12-12 03:13:37
问题 I want to convert Price format to number only with a php function Example 1 3,850,000,000 to 3850000000 Example 2 3.850.000.000 to 3850000000 Example 3 3-850-000-000 to 3850000000 回答1: Why not to use regular expressions? This should do the trick: $numbers = preg_replace('/[^0-9]/', '', $price); It's basically telling to match any non-numeric ( ^ stays for different from ) char and then to replace it with nothing. 回答2: You can also use preg_replace('/\D/', '', $number); \D matches all non

PHP number_format() decimal .99 is turned to .00

余生颓废 提交于 2019-12-12 02:50:05
问题 I want to turn a "dirty" figure into a properly written currency price. The input figure will be something like 23.99000 and I want to display 23,99 + the Euro symbol. I use this: $price = number_format($price, 2, ',', '')." €"; But the result will be 23,00 € instead of 23,99 €. What am I getting wrong? Thanks! 回答1: Try something like this: <?php $price = 23.99000; $price = sprintf("%01,2f", $price).' €'; echo $price; Output: 23,99 € the f means it'll treat the string as a float, and format

Float to currency in Java

跟風遠走 提交于 2019-12-12 01:16:20
问题 If a number (float) is input such as 12500, the number is converted to money format as 12,500.00. The format will be '###,###,###.##'. How to do this using java and without any apache utils or similar libraries. A comma will repeat after each 3 digits, and the decimal number will be rounded and shown as 2 digits after decimal places. If .5 it should be .50 and if .569 it should be .57. Is there any solution to this problem through regular expression or anything? 回答1: I found following code by

How to handle number format of OData Edm.Decimal in sapui5 correct?

南笙酒味 提交于 2019-12-11 16:42:06
问题 It looks like OData sends Edm.Decimal as "String" also containing the decimal separator. Question: What should be send by OData? Always the same values (for example separator with ".")? Question: How can this data be bound to SAPUI5 control with an automatic locale handling? I am already using new sap.ui.model.resource.ResourceModel({ But numbers are always shown with a dot as separator. 回答1: I think there is a bug in sap.ui.model.type.Float implementation. You can use that data type to

Display different numbers of decimals in an f-string depending on number's magnitude?

风格不统一 提交于 2019-12-11 14:48:45
问题 The goal is to use an f-string to round a float to a different number of decimal places based on the size of the number. Is there in-line f-string formatting that works like the following function? def number_format(x: float): if abs(x) < 10: return f"{x:,.2f}" # thousands seperator for consistency if abs(x) < 100: return f"{x:,.1f}" return f"{x:,.0f}" # this is the only one that actually needs the thousands seperator 回答1: Although it is not something that can go in-line in an f-string, the

Matlab wont shorten answer after format short

感情迁移 提交于 2019-12-11 14:03:26
问题 I'm trying to get matlab to shorten the answer into scientific notation but it continues to display long numbers. Here is my matlab script: syms E; kb=8.617e-5; %eV/k h=4.136e-15; %eV*s Ts=5760; %k q=1; %ev c=3.0e8; %m/s theta_s=atan(7e8/1.5e11); %rad format short Il_per_area = (q*pi/2)*(1-cos(2*theta_s))*int(((2/h^3*c^2)*E^2)/(exp(E/(kb*Ts-1))),E) This is the result matlab gave me: Il_per_area = (52508430427297951419542428146127404493579145286547868195529063488882991519987*exp(

JFormattedTextField with strict parsing number format

旧巷老猫 提交于 2019-12-11 13:44:11
问题 Since someone marked my other question (NumberFormat parse not strict enough) as duplicate by mistake and did not remove the duplicate label although I pointed out that it was different, I will post the question again together with my solution. Maybe it is helpful to someone. Here we go: I have a JFormattedTextField with a NumberFormat with Locale.US. So the decimal separator is the point and the grouping separator is the comma. Now I type the string "1,23" in this text field and move the