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
4
votes
3 answers

Counting digit occurrences

This problem is really confusing me; we're given two integers A, B, we want to count occurrences of digits in the range [A, B]. I though that if we could count the number of digit occurrences in the range [0, A] and [0, B], then the rest is trivial.…
Chris
  • 26,544
  • 5
  • 58
  • 71
4
votes
5 answers

Java SortMap Comparator to have digit keys ordered after letter keys

I need a SortedMap where the Charachter keys are sorted this way: ('A'..'Z'..'0'..'9'), so character first, then digits, all in ascending order. This is what I have tried so far, however, the output shows it fails in returning the sorting I want,…
pppccc
  • 43
  • 2
4
votes
4 answers

Problem on getting digits in a double variable

I got a little problem with a function I need in my java progam. I want to check the total amount of digits, a 'double' variable has. (e.g.: 5 should return 1, 5.0034 should return 5, and 2.04 should return 3.) My function is this: private int…
Hidde
  • 11,493
  • 8
  • 43
  • 68
4
votes
3 answers

Different rounding rule based on number of digits before the decimal

Say we have the following numerical vector: y=c(0.111,1.11,11.1,111.1) I would like it to be rounded as follows: 0.11,1.11,11.1,111 This rule is simple: I want three digits in total! But if the number is large (e.g. 1111 or 11111) then keep all…
user2862862
  • 111
  • 1
  • 1
  • 10
4
votes
6 answers

LeetCode: 1281. Subtract the Product and Sum of Digits of an Integer

I have been trying to figure out this question from LeetCoode. This is the problem: Given an integer number n, return the difference between the product of its digits and the sum of its digits. This is my code so far: /** * @param {number} n *…
4
votes
1 answer

how to printf a dynamic amount of placeholders in c?

Normally you have a set amount of placeholders in your printf(), which means I'd have to decide on a set amount of digit and string placeholders in advance. Is it possible to make the amount of placeholders in your printf() dynamic or make…
Pingu
  • 41
  • 4
4
votes
3 answers

Given a double, need to find how many digits in total

I have a double which is not necessarily positive but usually. It can be 0.xxxx000 or X.xxxx00000 or XX.00000 or 0.xxx0xxx00000, where eventually there are all 0's to the right of the last number. I need to keep track of how many digits there are.…
cdietschrun
  • 1,623
  • 6
  • 23
  • 39
4
votes
6 answers

Counting number of digits of input using python

I am trying to count the number of digits of an input. However, whenever I input 10 or 11 or any two digit number, the output is 325. Why doesn't it work? inputnumber = int(input()) countnumber = inputnumber digitcount = 0 while countnumber > 0: …
Naya Keto
  • 123
  • 3
  • 8
4
votes
2 answers

Objective C- How to add digits in a number?

How do I add the digits in a particular number for example if the number is 3234 the result should be 3+2+3+4 = 12?
nishantcm
  • 935
  • 5
  • 14
  • 28
4
votes
7 answers

javascript, best way to tell if a val is a single digit

whats the best way to tell if a value in javascript is a single digit. Ive been doing something like var valAsString = '' + val; if (valAsString.match(/\d/) {} clarification: I mean one of 0,1,2,3,4,5,6,7,8,9 Also, should what I have work? Im…
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
4
votes
3 answers

How can you get the number of digits contained in a double?

I'm trying to get the number of digits in the following double value: 56.46855976 without using converting it to a string (and simply replacing the "." with a ""). Anybody got any ideas?
Simian
  • 801
  • 1
  • 12
  • 20
4
votes
2 answers

Swift: just 1 fractional digits for NSLengthFormatter

I use the NSLengthFormatter to show the right entity like meters, feets, yards etc. The method works, but I don't get the right quantity of fractional digits. let distance = getDistanceAsDouble() //636.62084358567 in meters let format =…
kuzdu
  • 7,124
  • 1
  • 51
  • 69
4
votes
3 answers

function for counting digits and char in string in Matlab R2015

I have a string inside a cell, for example '5a5ac66'. I want to count the number of digits and chars in that string. '5a5ac66'= 4 digits (5566) and 3 chars (aac) How can I do that? Is there any function in MATLAB?
Ha Hacker
  • 387
  • 2
  • 6
  • 14
4
votes
1 answer

Neural Network for Recognition of Handwritten Digits in C#

I've gone through very good code project article about the Neural Network for Recognition of Handwritten Digits in C# by a code project contributor named Vietdungiitb. Here's the link for the Project…
LwHero
  • 41
  • 1
  • 3