Questions tagged [digits]

Questions dealing with getting, manipulating, or changing the digits of numbers

Use this tag for questions dealing with getting, manipulating, or changing the digits of numbers. More about digits on wikipedia

1098 questions
5
votes
2 answers

Modify a 4 digit number inside of a string and inserting colon

I have a string and i want to modify all 4 digit numbers and inserting colon between. Example: 1320 will become 13:20 $data = "The time is 1020 and the time is 1340 and 1550"; I'm thinking to use preg_match('/[0-9]{4}/', '????', $data); But not…
RG Servers
  • 1,726
  • 2
  • 11
  • 27
5
votes
4 answers

Java boolean-algorithm to check wheter number of digits is even

I´m trying to write a recursive method that returns true, if the count of digits of n displayed as a binary number is even and false if it is odd. I don´t really get how I can count in a recursive method, if it returns a boolean. I think part of the…
nicenoize
  • 99
  • 4
5
votes
3 answers

Store one decimal digit

I have a problem which concern with large number of small integers (actually decimal digits). What is the space efficient way to store such a data? Is it good idea to use std::bitset<4> to store one decimal digit?
dann
  • 119
  • 1
  • 3
5
votes
3 answers

bash add leading zeros to the count while number

I have the bash while loop using an initial count. I want to add %03d three digits to the count so that the output is like: folder001 folder002 my code is: #!/bin/bash input_file=$1 csv_file=$2 count=1 while IFS= read -r line…
passion
  • 1,000
  • 6
  • 20
  • 47
5
votes
8 answers

Sum all digits of a number and show the digits separately in Java

I've been using this site quite a lot but I've never really wrote anything. Today, I've stumbled upon a problem which solution I can't seem to find. The problem is that, I have an int variable with an unknown number of digits. It is asked of me to…
Doombringer
  • 596
  • 4
  • 19
5
votes
7 answers

Array Division - What is the best way to divide two numbers stored in an array?

I have two arrays (dividend, divisor): dividend[] = {1,2,0,9,8,7,5,6,6}; divisor[] = {9,8}; I need the result (dividend/divisor) as: quotient[] = {1,2,3,4,5,6,7}; I did this using array subtraction: subtract divisor from dividend until dividend…
josh
  • 13,793
  • 12
  • 49
  • 58
5
votes
5 answers

Number to digits without using strings nor division by 10

So there is this challenge in which you have to write a code which splits a number between 0-999 into digits without using string or division by 10. I've tried so hard and couldn't come up with the perfect algorithm. I got my code working for…
user3426112
  • 401
  • 1
  • 3
  • 11
5
votes
4 answers

C# decimal, how to add trailing zeros

I have to add trailing zeros to a decimal value. Not only for displaying (so Format is not an option), but in the actual underlying data, because the decimal precision is important in our application. I tried: decimal value = 1M decimal…
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
5
votes
4 answers

Sum of the digits of an integer in lua

I saw a question like this relating to Java and C, but I am using LUA. The answers might have applied to me, but I wasn't understanding them. Could someone please tell me how I would get the sum of the individual digits of an Integer. For Example. a…
Mikelong1994
  • 77
  • 2
  • 7
5
votes
8 answers

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?
MusicianCPlus
  • 53
  • 1
  • 1
  • 3
5
votes
7 answers

How to pad single-digit numbers with a leading 0

I am looping an array of one-digit and two-digit numbers. When printing these values, I need to ensure that all values are shown as two-digit numbers. I need a solution to prepend zeros to the single-digit numbers but leave the two-digit numbers…
matthewb
  • 3,462
  • 8
  • 37
  • 53
5
votes
3 answers

Regex to catch groups of same digits in Ruby

Is it possible to catch all grous of same digits in string with regex on Ruby? I'm not familiar with regex. I mean: regex on "1112234444" will produce ["111", "22", "3", "4444"] I know, I can use (\d)(\1*), but it only gives me 2 groups in each…
Airat Shigapov
  • 575
  • 4
  • 19
5
votes
3 answers

Java - How to search a string for 6 random numbers

I have a (large) string file in my application which contains a series of random character [a-Z] and [0-9] but also ";","/", "?", ":" and "@". I would like my application to tell me the nearest position where 6 digits are displayed consecutively (…
DVPeer
  • 63
  • 3
5
votes
1 answer

Ada Digits Confusion

I have been doing some reading, and I'm having a tough time understanding how to interpret something that is a "digits x". I.E. type something is digits 6 I get that it's 6 digits of precision, but I guess what has me mixed up is what does that…
onaclov2000
  • 5,741
  • 9
  • 40
  • 54
4
votes
6 answers

How would I count the number of digits to the right of the decimal in a floating point column?

I have table with Latitudes and Longitudes that are stored as floating points. How would I count the number of digits to the right of the decimal in the Latitude column? The data would look something like this: DECLARE @MyData TABLE (ID,…
user918967
  • 2,049
  • 4
  • 28
  • 43