number-formatting

Haskell - how to avoid scientific notation in decimal output

给你一囗甜甜゛ 提交于 2019-12-20 02:37:10
问题 I need to divide a list of numbers by 100 to be printed, for example: map (/100) [29, 3, 12] produces: [0.29,3.0e-2,0.12] however I need: [0.29,0.03,0.12] How do I do this in Haskell? Any ideas really appreciated. 回答1: 0.03 and 3.0e-2 are the same number. Internally, GHC uses showFloat to print it, which will result in the scientific notation whenever the absolute value is outside the range 0.1 and 9,999,999. Therfore, you have to print the values yourself, for example with printf from Text

Printing negative values as hex in python

醉酒当歌 提交于 2019-12-19 17:42:15
问题 I have the following code snippet in C++: for (int x = -4; x < 5; ++x) printf("hex x %d 0x%08X\n", x, x); And its output is hex x -4 0xFFFFFFFC hex x -3 0xFFFFFFFD hex x -2 0xFFFFFFFE hex x -1 0xFFFFFFFF hex x 0 0x00000000 hex x 1 0x00000001 hex x 2 0x00000002 hex x 3 0x00000003 hex x 4 0x00000004 If I try the same thing in python: for x in range(-4,5): print "hex x", x, hex(x) I get the following hex x -4 -0x4 hex x -3 -0x3 hex x -2 -0x2 hex x -1 -0x1 hex x 0 0x0 hex x 1 0x1 hex x 2 0x2 hex

Why Strings are not equal in my case?

时光怂恿深爱的人放手 提交于 2019-12-19 10:14:19
问题 I have currencyFormatter that is with se_SV locale. var currencyFormatter: NumberFormatter = { let formatter = NumberFormatter() formatter.currencySymbol = "" formatter.locale = Locale(identifier: "se_SV") formatter.minimumFractionDigits = 2 formatter.maximumFractionDigits = 2 formatter.numberStyle = .currencyAccounting formatter.isLenient = true return formatter }() I am converting NSNumber to String . let firstString = currencyFormatter.string(from: NSNumber(value: 22222222.50)) // "22 222

setlocale to fr-FR in PHP and number formatting

a 夏天 提交于 2019-12-19 08:53:51
问题 I am trying to create a French version of one of my sites. I have set setlocale(LC_ALL, 'fr_FR'); at the top of my page, and using strftime I am displaying dates correctly in the French style. However I am having some problems with a number. Part of the page uses data I am getting from a Web Service. I am assigning a returned value to a var like this: $overallRating = $returnArray['Overall']; I am then using the following code later to format it to 1 decimal place number_format($overallRating

setlocale to fr-FR in PHP and number formatting

£可爱£侵袭症+ 提交于 2019-12-19 08:53:45
问题 I am trying to create a French version of one of my sites. I have set setlocale(LC_ALL, 'fr_FR'); at the top of my page, and using strftime I am displaying dates correctly in the French style. However I am having some problems with a number. Part of the page uses data I am getting from a Web Service. I am assigning a returned value to a var like this: $overallRating = $returnArray['Overall']; I am then using the following code later to format it to 1 decimal place number_format($overallRating

Use Different Locale for @NumberFormat in Spring

谁都会走 提交于 2019-12-19 08:15:12
问题 I am working on a Spring 3 project and I need to format a Long field for Turkish currency. The default Locale of the application is en_US . I used the @NumberFormat annotation as below: @NumberFormat(style=NumberFormat.Style.CURRENCY) public Long getBudgetLimit() { return budgetLimit; } The annotation works and formats the form field in English locale. However I need to use Turkish locale for this field. Is there a way to set the locale of a single field or a page different than the

NumberFormat text field without commas

大城市里の小女人 提交于 2019-12-18 15:54:33
问题 I have a JFormattedTextField which I want to accept numbers in the 5 digit range. The following code works correctly: myNumberBox = new JFormattedTextField(NumberFormat.getIntegerInstance()); However, when I type "12345" into the field and switch focus, a comma is inserted due to my locale, making the text "12,345". How can I prevent commas from being added to my input? Better yet, can they be stripped out even if the user does insert commas? 回答1: You have to disable the grouping in your

How do I align the decimal point when displaying doubles and floats

自古美人都是妖i 提交于 2019-12-18 15:52:26
问题 If I have the following decimal point numbers: Double[] numbers = new Double[] {1.1233, 12.4231414, 0.123, 123.3444, 1.1}; for (Double number : numbers) { System.out.println(String.format("%4.3f", number)); } Then I get the following output: 1.123 12.423 0.123 123.344 1.100 What I want is: 1.123 12.423 0.123 123.344 1.100 回答1: The part that can be a bit confusing is that String.format("4.3", number) the 4 represents the length of the entire number(including the decimal), not just the part

How to display with n decimal places in Matlab

喜欢而已 提交于 2019-12-18 15:51:29
问题 I was wondering how to use command to set up displaying with n decimal places in Matlab? Must n be restricted to some predetermined numbers? Or one can just specify any for n? Thanks and regards! 回答1: You can convert a number to a string with n decimal places using the SPRINTF command: >> x = 1.23; >> sprintf('%0.6f', x) ans = 1.230000 >> x = 1.23456789; >> sprintf('%0.6f', x) ans = 1.234568 回答2: This site might help you out with all of that: http://herz-fischler.ca/MATLAB/section15.html 回答3:

Why is my toFixed() function not working?

末鹿安然 提交于 2019-12-18 12:07:51
问题 Here's the relevant code. I've confirmed with the alert that the correct number is saved, it's just not being changed to 2 decimal places. if ($(this).attr('name') == 'time') { var value = $(this).val(); parseFloat(value).toFixed(2); alert(value); editEntry.time = value; } 回答1: You're not assigning the parsed float back to your value var: value = parseFloat(value).toFixed(2); should fix things up. 回答2: Your conversion data is response[25] and follow the below steps. var i = parseFloat