number-formatting

Convert numbers into comma separated format with two decimals in javascript

99封情书 提交于 2019-12-23 10:10:14
问题 I am trying to convert numbers into comma separated format with two decimal places for each and every number in javascript: My code: Number(parseFloat(n).toFixed(2)).toLocaleString('en'); This code doesn't show two decimal places (.00) for whole numbers. I am expecting following results for a set of numbers: 10000 => 100,00.00 123233.12 => 123,233.12 300000.5 => 300,000.50 Appreciate your answer, thanks. 回答1: You can use the minimumFractionDigits option of the toLocaleString function. //

Matlab ShortEng number format via sprintf() and fprintf()?

最后都变了- 提交于 2019-12-23 09:42:21
问题 I like using MATLAB's shortEng notation in the interactive Command Window: >> a = 123e-12; >> disp(a); 1.2300e-10 % Scientific notation. Urgh! >> format shortEng; >> disp(a); 123.0000e-012 % Engineering notation! :-D But I want to use fprintf: >> format shortEng; >> fprintf('%0.3e', a); 1.2300e-10 % Scientific. Urgh! How do I print values with fprintf or sprintf with Engineering formatting using the MATLAB Format Operators? I know I could write my own function to format the values into

Number Format (Comma Separation) as per locale

*爱你&永不变心* 提交于 2019-12-23 09:37:31
问题 I have a requirement to show a number value like 123456789.905 in the following format 123,456,789.90 . But the comma separation changes depending on the locale selected in the phone (as if with US English selected comma separation is 3 places and if India English is selected it is like 12,34,56,789.90 ). How can I format my Double ? 回答1: So, java.text.NumberFormat doesn't slove the problem, unfortunately, but com.ibm.icu.text.NumberFormat does. You can use this: Double d = 123456789.905; com

Number and date format : altering NLS_SESSION_PARAMETER does not work?

…衆ロ難τιáo~ 提交于 2019-12-23 09:00:43
问题 Oracle 11.2.0.3.0, APEX 4.1.1.00.23. We need to display numbers in our application with the format FM999999999990.000 and dates with the English format DD-MON-YYYY . Even if the application language is going to change (french, spain, etc.), we always need this format for numbers (no space or comma for group separator, and a point for decimal separator, ie. -1254.010 ) and date (3 first letters from the English month name ie. 12-FEB-2012 ). Here are globalization attributes we are using (

Floating point number format

点点圈 提交于 2019-12-23 08:13:52
问题 I want to use number_format function in PHP. For example: $number = 234.51; echo number_format($number,2); This works for float numbers but I want to use it for different numbers. If a number is decimal and doesn't have any floating points, it shows like : 145.00 . How can I fix this? I mean I want to show as many floating points as needed, not more. 回答1: Investigate the printf and sprintf functions instead of number_format . They give the ability to format numbers as you wish. printf("%d",

Floating point number format

自古美人都是妖i 提交于 2019-12-23 08:12:50
问题 I want to use number_format function in PHP. For example: $number = 234.51; echo number_format($number,2); This works for float numbers but I want to use it for different numbers. If a number is decimal and doesn't have any floating points, it shows like : 145.00 . How can I fix this? I mean I want to show as many floating points as needed, not more. 回答1: Investigate the printf and sprintf functions instead of number_format . They give the ability to format numbers as you wish. printf("%d",

Why does the Standard Numeric Format for percentages include a space?

喜夏-厌秋 提交于 2019-12-23 07:36:02
问题 The Back Story I have some decimal values which I am displaying as strings on a web page as part of a larger string. I started off using a Standard Numeric Format String to output this. E.g. myDecimal.ToString("P0") The 0 after the P tells it I want no decimal places. This works as far as it goes, in that my ouput ends up looking something like: Calculated as above based on the phased minimum Company contribution rate of 2 % The Space Problem I really want to get rid of that space between the

Performant way of formatting numbers according to the user's locale with iostream?

 ̄綄美尐妖づ 提交于 2019-12-23 03:39:35
问题 In one part of our application there is the requirement to format numbers according to the user's locale. The interface essentially looks like this: std::string format_number(double number); The old implementation looked like this: std::string format_number(double number) { using namespace std; static const locale user_loc(""); ostringstream fmtstream; fmtstream.imbue(user_loc); fmtstream << std::fixed; fmtstream << number; return fmtstream.str(); } We have now noticed that with our compiler

Convert number into culture specific

主宰稳场 提交于 2019-12-22 14:18:09
问题 I have a number like 202667.4 . I want to convert this to number based on culture . For Ex: In "de"(German) the number should be in 202.667,40 . Any help will be greatly appreciated. Thanks. 回答1: If you want to represent existing number (say, double ) in culture specific format, try formatting : https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings double source = 202667.4; // "n" - ... group separators, and a decimal separator with optional negative sign

Round positive value half-up to 2 decimal places in C

扶醉桌前 提交于 2019-12-22 05:19:09
问题 Typically, Rounding to 2 decimal places is very easy with printf("%.2lf",<variable>); However, the rounding system will usually rounds to the nearest even . For example, 2.554 -> 2.55 2.555 -> 2.56 2.565 -> 2.56 2.566 -> 2.57 And what I want to achieve is that 2.555 -> 2.56 2.565 -> 2.57 In fact, rounding half-up is doable in C, but for Integer only; int a = (int)(b+0.5) So, I'm asking for how to do the same thing as above with 2 decimal places on positive values instead of Integer to achieve