number-formatting

Suppress exponential formatting in figure ticks

半城伤御伤魂 提交于 2019-11-26 08:26:13
问题 Tick labels for ticks bigger than about 10\'000, get formatted to 1x10^4 for example. Whereas the exponential part appears above the corresponding axes. This misbehavior has been well described on on matlab central as well, but without a solution. Thanks for your help. The \'quick trick\' set(gca, \'YTickLabel\',get(gca,\'YTick\')) did not work when applied to bar3, as can be seen on the following figure. 回答1: One way to get better control over tick labels, and to avoid the exponential

How to format a number 0..9 to display with 2 digits (it's NOT a date)

可紊 提交于 2019-11-26 07:58:45
问题 I\'d like to always show a number under 100 with 2 digits (example: 03, 05, 15...) How can I append the 0 without using a conditional to check if it\'s under 10? I need to append the result to another String, so I cannot use printf. 回答1: You can use: String.format("%02d", myNumber) See also the javadocs 回答2: If you need to print the number you can use printf System.out.printf("%02d", num); You can use String.format("%02d", num); or (num < 10 ? "0" : "") + num; or (""+(100+num)).substring(1);

Java : JFormattedTextField saving numbers

南楼画角 提交于 2019-11-26 07:49:22
问题 In my application I want to input numbers (amounts) to a specific limit, and hence have used JFormattedTextField. Limit like \"12345678.99\" i.e. 8 digits before \".\" and 2 after \".\" or so on. This is my implementation code, but it doesn\'t result as expected. startBalTxt.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat(\"########.##\")))); startBalTxt.setText(resourceMap.getString(\"startBalTxt.text\")); //

Decimal separator in NumberFormat

瘦欲@ 提交于 2019-11-26 07:44:04
问题 Given a locale java.text.NumberFormat: NumberFormat numberFormat = NumberFormat.getInstance(); How can I get the character used as Decimal separator (if it\'s a comma or a point) in that numberformat? How can I modify this property without having to use new DecimalFormat(format)? Thanks 回答1: The helper class DecimalFomatSymbols is what you are looking for: DecimalFormat format=DecimalFormat.getInstance(); DecimalFormatSymbols symbols=format.getDecimalFormatSymbols(); char sep=symbols

How to parse number string containing commas into an integer in java?

邮差的信 提交于 2019-11-26 07:36:49
问题 I\'m getting NumberFormatException when I try to parse 265,858 with Integer.parseInt() . Is there any way to parse it into an integer? 回答1: Is this comma a decimal separator or are these two numbers? In the first case you must provide Locale to NumberFormat class that uses comma as decimal separator: NumberFormat.getNumberInstance(Locale.FRANCE).parse("265,858") This results in 265.858 . But using US locale you'll get 265858 : NumberFormat.getNumberInstance(java.util.Locale.US).parse("265,858

JQuery Number Formatting

梦想与她 提交于 2019-11-26 07:33:16
问题 There are way too many questions and answers about this basic functionality, I cannot see the wood for the trees. In Java there is only one simple answer ( java.text.NumberFormat and its subclasses) so I\'m sure the majority of plugins, questions and answers will mature eventually to a de-facto standard for JQuery. This plugin is the best I found so far, but I don\'t know if it\'s still developed, is mature etc. http://plugins.jquery.com/project/numberformatter Is there a better solution? Is

How to format numbers similar to Stack Overflow reputation format

妖精的绣舞 提交于 2019-11-26 06:43:52
问题 I want to convert a number into a string representation with a format similar to Stack Overflow reputation display. e.g. 999 == \'999\' 1000 == \'1,000\' 9999 == \'9,999\' 10000 == \'10k\' 10100 == \'10.1k\' 回答1: Another approach that produces exactly the desired output: function getRepString (rep) { rep = rep+''; // coerce to string if (rep < 1000) { return rep; // return the same number } if (rep < 10000) { // place a comma between return rep.charAt(0) + ',' + rep.substring(1); } // divide

Show only two digit after decimal [duplicate]

给你一囗甜甜゛ 提交于 2019-11-26 06:33:13
问题 This question already has an answer here: how to convert double to 2 number after the dot? [duplicate] 6 answers How to get the double value that is only two digit after decimal point. for example if i=348842. double i2=i/60000; tv.setText(String.valueOf(i2)); this code generating 5.81403333 . But I want only 5.81 . So what shoud I do? 回答1: Use DecimalFormat. DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it

How to format numbers by prepending 0 to single-digit numbers?

牧云@^-^@ 提交于 2019-11-26 05:52:58
问题 I want to format a number to have two digits. The problem is caused when 0 – 9 is passed, so I need it to be formatted to 00 – 09 . Is there a number formatter in JavaScript? 回答1: The best method I've found is something like the following: (Note that this simple version only works for positive integers) var myNumber = 7; var formattedNumber = ("0" + myNumber).slice(-2); console.log(formattedNumber); For decimals, you could use this code (it's a bit sloppy though). var myNumber = 7.5; var dec

Add comma to numbers every three digits

谁说胖子不能爱 提交于 2019-11-26 05:49:13
问题 How can I format numbers using a comma separator every three digits using jQuery? For example: ╔═══════════╦═════════════╗ ║ Input ║ Output ║ ╠═══════════╬═════════════╣ ║ 298 ║ 298 ║ ║ 2984 ║ 2,984 ║ ║ 297312984 ║ 297,312,984 ║ ╚═══════════╩═════════════╝ 回答1: @Paul Creasey had the simplest solution as the regex, but here it is as a simple jQuery plugin: $.fn.digits = function(){ return this.each(function(){ $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); }) } You