numbers

Parse currency into numbers in Python

◇◆丶佛笑我妖孽 提交于 2019-12-28 06:35:49
问题 I just learnt from Format numbers as currency in Python that the Python module babel provides babel.numbers.format_currency to format numbers as currency. For instance, from babel.numbers import format_currency s = format_currency(123456.789, 'USD', locale='en_US') # u'$123,456.79' s = format_currency(123456.789, 'EUR', locale='fr_FR') # u'123\xa0456,79\xa0\u20ac' How about the reverse, from currency to numbers, such as $123,456,789.00 --> 123456789 ? babel provides babel.numbers.parse_number

What's a C# regular expression that'll validate currency, float or integer?

孤者浪人 提交于 2019-12-28 06:33:00
问题 What is a regular expression suitable for C# that'll validate a number if it matches the following? $1,000,000.150 $10000000.199 $10000 1,000,000.150 100000.123 10000 Or the negative equivalents? 回答1: You can use csmba's regex if you make one slight modification to it. ^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$ 回答2: I think ssg is right. It's not a really good use of Regex, especially if your software has to deal with non-US centric data entry. For instance, if the currency

How can I handle numbers bigger than 17-digits in Firefox/IE7?

流过昼夜 提交于 2019-12-28 06:32:28
问题 For a web application I want to be able to handle numbers up to 64 bits in size. During testing, I found that javascript (or the browser as a whole) seems to handle as much as 17 digits. A 64-bit number has a maximum of 20 digits, but after the javascript has handled the number, the least significant 3 digits are rounded and set to 0.... Any ideas where this comes from? More importantly, any idea how to work around it? 回答1: In Javascript, all numbers are IEEE double precision floating point

is it ok to specialize std::numeric_limits<T> for user-defined number-like classes?

非 Y 不嫁゛ 提交于 2019-12-28 06:17:10
问题 The documentation of std::numeric_limits<T> says it should not be specialized for non-fundamental types. What about number-like user-defined types? If I define my own type T which represents a numeric value and overloads numeric operators, and for which the information represented by numeric_limits makes sense -- will anything break if I specialize numeric_limits for that type? 回答1: Short answer: Go ahead, nothing bad will happen. Long answer: The C++ standard extensively protects the ::std

Best way to convert English numbers to Arabic [duplicate]

こ雲淡風輕ζ 提交于 2019-12-28 05:10:27
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Convert String to another locale in java I want to convert a java String that contains english numbers to arabic one's so i make this int arabic_zero_unicode= 1632; String str = "13240453"; StringBuilder builder = new StringBuilder(); for(int i =0; i < str.length(); ++i ) { builder.append((char)((int)str.charAt(i) - 48+arabic_zero_unicode)); } System.out.println("Number in English : "+str); System.out.println(

Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array

核能气质少年 提交于 2019-12-28 05:07:07
问题 I don't seem to understand how Integer.MAX_VALUE and Integer.MIN_VALUE help in finding the min and max value in an array. I understand how this method (pseudocode below) works when finding the min and max values: max = A[0], min = A[0] for each i in A if A[i] > max then max = A[i] if A[i] < min then min = A[i] But as for this method, I don't understand the purpose of Integer.MAX_VALUE and Integer.MIN_VALUE : import java.util.Scanner; class MyClass { public static void main(String[] args) {

Why int j = 012 giving output 10?

 ̄綄美尐妖づ 提交于 2019-12-28 04:24:05
问题 In my actual project It happened accidentally here is my modified small program. I can't figure out why it is giving output 10 ? public class Int { public static void main(String args[]) { int j=012;//accidentaly i put zero System.out.println(j);// prints 10?? } } After that, I put two zeros still giving output 10. Then I change 012 to 0123 and now it is giving output 83? Can anyone explain why? 回答1: Than I change 012 to 0123 and now it is giving output 83? Because, it's taken as octal base

Formatting Numbers as Strings with Commas in place of Decimals

点点圈 提交于 2019-12-28 04:13:22
问题 I have the following number: 4.3 I'd like to display this number as 4,3 for some of our European friends. I was under the impression that the following line would do the trick: string ret = string.Format("{0:0,0}", 4.3); // returns "04", not "4,3" Am I using the incorrect string? 回答1: I think: string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:0.0}", 4.3); should do what you want. 回答2: NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = ",";

jquery get number from id

Deadly 提交于 2019-12-28 04:02:05
问题 how can i get the number from a div tag's id? example: <div id="button1"></div> how can i get the 1 and store it in a variable? 回答1: var id = $("div").attr('id').replace(/button/, ''); 回答2: Your "id" values cannot be purely numeric; they need to start with a letter or "_" like an identifier. ( Note : that's not true in HTML5 documents.) Once you've got a number in your "id" value like that, you would just use the jQuery attr() function to get the id: var theId = parseInt($('div.whatever')

Number format, writing 1e-5 instead of 0.00001

▼魔方 西西 提交于 2019-12-28 03:01:08
问题 I've used read.table to read a file that contains numbers such as 0.00001 when I write them back with write.table those numbers appear as 1e-5 How can I keep the old format? 回答1: You can do this by converting your numbers to strings with formatting as you require, then using the argument quote = FALSE in the call to write.table . dfr <- data.frame(x = 10^(0:15)) dfr$y <- format(dfr$x, scientific = FALSE) write.table(dfr, file = "test.txt", quote = FALSE) Note that you shouldn't need to change