digits

How to round a number to n decimal places in Java

What I'd like is a method to convert a double to a string which rounds using the half-up method. I.e. if the decimal to be rounded is a 5, it always rounds up the previous number. This is the standard method of rounding most people expect in most situations. I also would like only significant digits to be displayed. That is there should...

Extracting individual digits from a float

I have been banging my head on this one all day. The C++ project I am currently working on has a requirement to display an editable value. The currently selected digit displays the incremented value above and decremented value below for said digit. It is useful to be able to reference the editable value as both a number and collection...

Delete digits in Python (Regex)

I'm trying to delete all digits from a string. However the next code deletes as well digits contained in any word, and obviously I don't want that. I've been trying many regular expressions with no success. Thanks! s = "This must not b3 delet3d, but the number at the end yes 134411" s = re.sub("\d+", "", s) print s Result: This...

C/C++ Identify the digits in a given number.

Hello everyone, i'm new to programming.. and i'm stuck at a problem.. I want my program to identify the separate digits in a given number, like if i input 4692, it should identify the digits and print 4 6 9 2. And yeah, without using arrays.. Thanks in advance! ...

Extract first two digits of hex (UInt32 *) and convert to int

I have a bunch of hex values stored as UInt32* 2009-08-25 17:09:25.597 Particle[1211:20b] 68000000 2009-08-25 17:09:25.598 Particle[1211:20b] A9000000 2009-08-25 17:09:25.598 Particle[1211:20b] 99000000 When I convert to int as is, they're insane values when they should be from 0-255, I think. I think I just need to extract the firs...

Efficient way to determine number of digits in an integer

What is a very efficient way of determining how many digits there are in an integer in C++? ...

Ruby: counting digits in a float number

Is there any worthy Ruby method to count the number of digits in a float? Also, how do I specify the precise when to_s float numbers? ...

What programming language will enable me to enter a very long number without converting it to floating point?

What would be the best way to do the following. Enter a very long number, lets say 500,000 digits long without it going into scientific notation; and then am able to do math with it, like +2 etc.? Thank you in advance. EDIT: It is a 500,000 digit, positive integer. ...

C#: Anything similar to the php ctype_digit function for C#?

I have a string and I want to check that it only consists of digits. I don't really want to (or need to) parse it or anything, I just want to know that it does not contain anything but digits (and no floating point separator either, just digits). PHP has this nice function called ctype_digit. Is there anything similar for C# anywhere in...

Check if string contains only digits

Hello I want to check if a string contains only digits. I used this: var isANumber = isNaN(theValue) === false; if (isANumber){ .. } .. but realized that it also allows + and -. Basically I wanna make sure the input contains ONLY digits and no other letters. Since +100 and -5 are both numbers, isNaN, is not the right way to go. ...

Library or code to convert digit in letters

Could you suggest me a code or a library (possibly java) to convert digits (e.g. 24) in letters (e.g. twenty-four)? Obviously I need to change locale (from English to Italian). Thank you in advance and sorry for my English... Fabio ...

Multiplying two number arrays

Can anyone please tell me how to multiply two number arrays in C? The number arrays are basically derived from two strings containing digits. eg: 123456 and 132465. Edit: I had two string as S1 = "123456" and S2="132546". I then converted these two strings into array of ints i.e. int IS1[6] and IS2[6] so that IS1[1] = 1, IS1[2] = 2......

Scilab - limit to the number of digits

hello! my project is to create a program that will test whether a number is prime or not. the code is ready. but when i enter a 19 digit prime for example, the code immediately outputs "composite". i'm quite sure it is because it treats the last few digits of the number as zeroes. is there a way to store more than 16 digits in scilab? ...

Inserting spaces between digits in C

How would I go about taking a number like 123456 and having it print as 1 2 3 4 5 6? ...

Controlling digits in R

There is an option in R to get control over digit display. For example: options(digits=10) is supposed to give the calculation results in 10 digits till the end of R session. In the help file of R, the definition for digits parameter is as follows: digits: controls the number of digits to print when printing numeric values. It...

Sorting digits in a string alphabetically

We have a list of titles, some of which start with numbers (e.g. 5 Ways to Make Widgets). We would like to sort this as if it were "Five Ways..." without changing the title. We know that some movie places do this, but I can't find info online on how to do it. Any ideas? ...

Given a number series, finding the Check Digit Algorithm...???

Suppose I have a series of index numbers that consists of a check digit. If I have a fair enough sample (Say 250 sample index numbers), do I have a way to extract the algorithm that has been used to generate the check digit? I think there should be a programmatic approach atleast to find a set of possible algorithms. UPDATE: The lengt...

Python - Number of Significant Digits in results of division

Newbie here. I have the following code: myADC = 128 maxVoltage = 5.0 maxADC = 255.0 VoltsPerADC = maxVoltage/maxADC myVolts = myADC * VoltsPerADC print "myADC = {0: >3}".format(myADC) print "VoltsPerADC = {0: >7}".format(VoltsPerADC) print VoltsPerADC print "myVolts = {0: >7}".format(myVolts) print myVolts This outputs the following...

Prolog: find all numbers of unique digits that can be formed from a list of digits

The best thing I could come up with so far is this function: numberFromList([X], X) :- digit(X), !. numberFromList(List, N) :- member(X, List), delete(List, X, LX), numberFromList(LX, NX), N is NX * 10 + X. where digit/1 is a function verifying if an atom is a decimal digit. The numberFromLis...

Fastest way to pad a number in Java to a certain number of digits

Am trying to create a well-optimised bit of code to create number of X-digits in length (where X is read from a runtime properties file), based on a DB-generated sequence number (Y), which is then used a folder-name when saving a file. I've come up with three ideas so far, the fastest of which is the last one, but I'd appreciate any adv...