number-formatting

android: how do I format number as phone with parentheses

蹲街弑〆低调 提交于 2019-11-30 12:42:12
I have a number that I need to format as a telephone number. If I do PhoneNumberUtils.formatNumber(numStr); Then I get 888-555-1234 But what I need to get is (888) 555-1234 How do I get the second one? Is there a standard android way? If you know the country for which you want to do it, you can use Google's open source library libphonenumber . Here is how you can format it: String numberStr = "8885551234" PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { PhoneNumber numberProto = phoneUtil.parse(numberStr, "US"); //Since you know the country you can format it as follows: System

PHP number_format is rounding?

拜拜、爱过 提交于 2019-11-30 12:39:45
I have a price "0,10" or "00000,10" Now when i try number_format($price, 2, ',', '') I get 0,00. How can i fix this? I want 0,10 $. I don't want rounding. Or when i have 5,678, i get 5,68. But i want 5,67. You can increase the size of the number before rounding down with floor : $price = floor($price * 100) / 100; $formatted = number_format($price, 2, ',', ''); Another solution, which may give better precision since it avoids floating-point arithmetic, is to format it with three decimals and throw away the last digit after formatting: $formatted = substr(number_format($price, 3, ',', ''), 0,

Is there a Java number formatting library that handles significant digits?

℡╲_俬逩灬. 提交于 2019-11-30 11:48:14
The built in DecimalFormat only allows you to specify number of digits to the right of the decimal place. Because of the limitations of representing numbers as double, number formatting needs to include some level of rounding inside of it. In the general case, that rounding has to be to a number of significant digits (default case is the precision of a double) or else your formatted double will end up showing stuff like 3.5999999 instead of 3.6. The closest solution I could find is using new BigDecimal(double, new MathContext(14, RoundingMode.HALF_EVEN).stripTrailingZeros().toPlainString()

How to set tooltips to display percentages to match axis in Google Visualization Line Chart?

孤人 提交于 2019-11-30 11:18:51
The tooltips can be set to display percentages using the following code: var formatter = new google.visualization.NumberFormat({ fractionDigits: 2, suffix: '%' }); formatter.format(data, 1); // Apply formatter to first column. Is there a way for NumberFormat to multiply each element by 100? Otherwise the tooltip appears as .50%. I am using vAxis.format = "format:'#%' " which does multiply by 100. So .5 is displayed as 50% on the vertical axis. According to the documentation( icu-project.org/apiref ), this can be overwritten by enclosing the % in single quotes, but this did not work. The net

NumberFormat.getCurrencyInstance() not returning currency symbol for Locales CHINA and FRANCE (jdk-1.8)

谁说我不能喝 提交于 2019-11-30 09:50:47
问题 I have written a program to return double values with the currency symbols of some countries. For this I am using getCurrencyInstance() method to get symbol of particular country. The problem is specific to my laptop's JDK-1.8 and works fine on online compiler. The problem, I am facing is that the currency symbol for CHINA and FRANCE are represented with '?'. But for INDIA and US , correct symbols are shown. I am working on this problem for a bit now. Hence, any leads would be helpful. Here

How to get the pattern of Number Format of a specific locale?

让人想犯罪 __ 提交于 2019-11-30 09:26:33
问题 I have a simple question: How to get the pattern used to format a number using NumberFormat created for a specific locale as shown below: import java.util.Locale; Locale aLocale = new Locale("fr","CA"); NumberFormat numberFormat=NumberFormat.getNumberInstance(aLocale); Here I want to know the pattern used to format a number in French language and the country of Canada . For e.g. : a number 123456.7890 is converted into 123 456,789 after formatting it means pattern may be # ###,### for above

MVC3 edit for decimal fields and localization

北战南征 提交于 2019-11-30 09:00:04
My locale uses a comma , , and not a dot . for decimal separator. In MVC3, when I open an Edit view where the decimal values are shown with @Html.EditorFor(model => model.MyDecimalVal) the value is shown correctly. When I enter value with comma, I get error "Value is not a number" and if I enter value with dot, I get no error, but actually no value is saved. How to handle this situation? Getting around with this by tweaking your validation logic has been already explained so here is a different approach. Put the below code inside your web.config file under the <system.web> node if you would

Java7 Double.toString() returns 0.005 / java6 it is 0.0050

荒凉一梦 提交于 2019-11-30 06:03:00
I am upgrading from JDK6 to JDK7 . The following code demonstrate shows a minor change in Double.toString() public class StringDemo { public static void main(String[] args) { System.out.println(Double.toString(.0005)); System.out.println(Double.toString(.005)); //different string System.out.println(Double.toString(.05)); System.out.println(Double.toString(.5)); } } JRE6 5.0E-4 0.0050 0.05 0.5 JRE7 I am looking for any documentation related to above change. The compatibility page does not cover it. 5.0E-4 0.005 //changed. 0.05 0.5 The output was saved in many reference files, and compared by

Why is my toFixed() function not working?

二次信任 提交于 2019-11-30 05:37:29
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; } You're not assigning the parsed float back to your value var: value = parseFloat(value).toFixed(2); should fix things up. Your conversion data is response[25] and follow the below steps. var i = parseFloat(response[25]).toFixed(2) console.log(i)//-6527.34 Example simple (worked): var a=Number.parseFloat($("#budget_project")

C++ complex numbers, what is the right format?

落爺英雄遲暮 提交于 2019-11-30 03:35:58
I want to use C++ with complex numbers. Therefore I included #include <complex> . Now my question is: How do I declare a variable?(so what is the format called for let's say: 1 + i ?) Thanks in advance :-) // 1 + 2i std::complex<double> c(1, 2); The constructor of std::complex has two parameters: The first, wich has the real part of the number. The second, wich has the imaginary part of the number. For example: std::complex<float> my_complex(1,1); //1 + 1i Also, C++11 introduces user defined literals , wich allows us to implement (Or be implemented by the standard library, as in this C++14