converting a number base 10 to base 62 (a-zA-Z0-9)

OLD: A quick and dirty solution can be to use a function like this: function toChars($number) { $res = base_convert($number, 10,26); $res = strtr($res,’0123456789′,’qrstuvxwyz’); return $res; } The base convert translate your number to a base where the digits are 0-9a-p then you get rid of the remaining digits with a quick char substitution. As … Read more

angularjs: allows only numbers to be typed into a text box

This code shows the example how to prevent entering non digit symbols. angular.module(‘app’). directive(‘onlyDigits’, function () { return { restrict: ‘A’, require: ‘?ngModel’, link: function (scope, element, attrs, modelCtrl) { modelCtrl.$parsers.push(function (inputValue) { if (inputValue == undefined) return ”; var transformedInput = inputValue.replace(/[^0-9]/g, ”); if (transformedInput !== inputValue) { modelCtrl.$setViewValue(transformedInput); modelCtrl.$render(); } return transformedInput; }); … Read more

Is there a BigFloat class in C#?

Perhaps you’re looking for BigRational? Microsoft released it under their BCL project on CodePlex. Not actually sure how or if it will fit your needs. It keeps it as a rational number. You can get the a string with the decimal value either by casting or some multiplication. var r = new BigRational(5000, 3768); Console.WriteLine((decimal)r); … Read more

Generic constraint to match numeric types [duplicate]

In this case you want to constrain your generic to the IComparable interface, which gives you access to the CompareTo method, since this interface allows you to answer the question ShouldBeGreaterThan. Numeric types will implement that interface and the fact that it also works on strings shouldn’t bother you that much.

How to convert a number to string and vice versa in C++

Update for C++11 As of the C++11 standard, string-to-number conversion and vice-versa are built in into the standard library. All the following functions are present in <string> (as per paragraph 21.5). string to numeric float stof(const string& str, size_t *idx = 0); double stod(const string& str, size_t *idx = 0); long double stold(const string& str, … Read more