numbers

set caret back to it's original place after formating number

若如初见. 提交于 2019-12-11 11:33:55
问题 I have an input field which has a data manipulation and is a decimal field. Everything works fine except when I put in more than 3 numbers it will lose the current caret and set it to the end of the field because of the field formatting. Example: 123 works fine 1234 will result in 1’234.00 and the caret is after the last 0. How is it possible to set the caret back to its original position? (Between 4 and the .) function thousenderSign(number) { number = '' + number; if (number.length > 3) {

JTextField with regex applied won't accept value until AFTER the Document is applied

早过忘川 提交于 2019-12-11 11:00:58
问题 I have a JTextField that I have overridden the Document for, so that I can prevent the user from entering some characters. The way this works is my extension of Document receives a Regex in its constructor, then checks anything the user types against the Regex: public class ValidDocument extends PlainDocument { private String regex; public ValidDocument(String regex) { this.regex = regex; } @Override public void insertString(int offs, String str, AttributeSet a) { if(str == null) return; try

I want to check for both negative number and non-number

戏子无情 提交于 2019-12-11 10:54:25
问题 I have code to check for non numbers but also wish to include a check for negative numbers. If the number is negative or not a number, they have to re-enter info. I tried putting an if(depValue < 0).... after try{ and before catch but that didn't work. It doesn't make sense to me if I were to put the if statement after the while loop. String depIn = ""; BufferedReader depositInput = new BufferedReader(new InputStreamReader(System.in)); while(true){ System.out.print("Amount to deposit: ");

Python - Regular expressions get numbers between parenthesis

我的梦境 提交于 2019-12-11 10:53:46
问题 I need help creating a Regex to get numbers between parenthesis when my values are between word "PIC" and the "." I got this records and need to be able to extract values between () PIC S9(02)V9(05). I need this result "02 05" PIC S9(04). I need this result "04" PIC S9(03). I need this result "03" PIC S9(03)V9(03). I need this result "03 03" PIC S9(02)V9(03). I need this result "02 03" PIC S9(04). I need this result "04" PIC S9(13)V9(03). I need this result "13 03" I have try the below but it

What would be a good way of determining number of decimal places from a format string?

寵の児 提交于 2019-12-11 10:35:26
问题 I'd like a function that looks like this: int GetDecimalPlaces(string format, IFormatProvider formatProvider = null); The inputs would be exactly the same as those which can be legally passed to methods responsible for formatting numbers, e.g., double.ToString , decimal.ToString . The output would be an int indicating the lowest number of decimal places required by the format string. So here are a couple of example inputs/outputs I would expect (let's just say leaving formatProvider as null

Convert strings to numbers without losing decimals

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:28:15
问题 I'm developing a map and I have to save this parameters on Parse database: lat.: 20.6350 . Long: -103.5334 The problem is when i convert them into numbers, that function converts 20.6350 to 20.635. ¿What can I do in order tu preserve the last zero? 回答1: You should specify the sig figs and they will display properly. $lat = "20.6350"; $lng = "-103.5334"; print number_format($lat, 4); // 4 sig figs print number_format($lng, 4); See http://php.net/number_format for additional formatting info

C++ random numbers logical operator wierd outcome

五迷三道 提交于 2019-12-11 10:16:52
问题 I am trying to make a program generating random numbers until it finds a predefined set of numbers (eg. if I had a set of my 5 favourite numbers, how many times would I need to play for the computer to randomly find the same numbers). I have written a simple program but don't understand the outcome which seems to be slightly unrelated to what I expected, for example the outcome does not necessarily contain all of the predefined numbers sometimes it does (and even that doesn't stop the loop

How to find the place value for the given decimal value through php?

*爱你&永不变心* 提交于 2019-12-11 10:04:42
问题 I'm not so familiar with php, but i know we could find the place value of a given number through php. For example if the input is 23.56 it should echo 2 - Tens, 3 - Ones, 5 - Hundredths, 6 - Thousandths. Any idea would be appreciated. :) please help. 回答1: Try $str = '23.56'; $strdiv = explode('.', $str); $before = array('Tens', 'Ones'); $after = array('Hundredths', 'Thousandths'); $counter = 0; foreach($strdiv as $v) { for($i=0; $i<strlen($v); $i++) { if(!empty($v)) { if($counter == 0) {

How to write common function for keypress function check for floating number of a textbox in C#?

痞子三分冷 提交于 2019-12-11 09:53:19
问题 I want to call a common function for more than 2 textboxes so that keypress can check that only floating point number can take a input. This is my sample code: this work only for a single textbox ( tbL1Distance ). But I want it as a common textbox control. private void tbL1Distance_KeyPress(object sender, KeyPressEventArgs e) { char ch = e.KeyChar; if (ch == 46 && tbL1Distance.Text.IndexOf('.') != -1) { e.Handled = true; return; } if (!Char.IsDigit(ch) && ch != 8 && ch != 46) { e.Handled =

How to convert locale formatted number to BigInteger in Java?

心已入冬 提交于 2019-12-11 09:49:45
问题 I searched a lot but nothing helped me :( Suppose I need convert 12.090.129.019.201.920.192.091.029.102.901.920.192.019.201.920 (in Portuguese group separator: .) to BigInteger value. How to do that conversion? I tried use NumberFormat, DecimalFormat and nothing works or I didn't on right way :( 回答1: Get a NumberFormat instance for a Portuguese Locale, and then parse the number with it. This will also handle locale-specific decimal separators. NumberFormat nf = NumberFormat.getNumberInstance