numbers

jquery get number from id

不想你离开。 提交于 2019-11-27 13:59:41
how can i get the number from a div tag's id? example: <div id="button1"></div> how can i get the 1 and store it in a variable? var id = $("div").attr('id').replace(/button/, ''); Your "id" values cannot be purely numeric; they need to start with a letter or "_" like an identifier. ( Note : that's not true in HTML5 documents.) Once you've got a number in your "id" value like that, you would just use the jQuery attr() function to get the id: var theId = parseInt($('div.whatever').attr('id').replace(/[^\d]/g, ''), 10); // replace all non-digits with nothing alert($('div').attr("id").replace(/\D

Is there a functionality in JavaScript to convert values into specific locale formats?

做~自己de王妃 提交于 2019-11-27 13:53:01
Is there a built in function of JavaScript to convert a string into a particular locale (Euro in my case)? E.g. 50.00 should get converted to 50,00 € . Matt Ball 50.00 is a unit-less value. The best you can do is convert 50.00 to 50,00 and then append the € yourself. Therefore, just use Number.toLocaleString() . var i = 50.00; alert(i.toLocaleString() + ' €'); // alerts '50.00 €' or '50,00 €' Demo → Lots of relevant questions: How can I format numbers as money in JavaScript? (the big one; ~70k views) Convert to currency format Format currency using javascript how do i print currency format in

Convert number into xx.xx million format? [closed]

空扰寡人 提交于 2019-11-27 13:50:01
Is there a simple way to convert a high number e.g. 14120000 into 14.12 million format with PHP? I've been looking at number_format but it doesn't seem to offer this function, also thought about sub_str to separate the digits out, but thought there might be a better way? Try this from, https://php.net/manual/en/function.number-format.php#89888 : <?php function nice_number($n) { // first strip any formatting; $n = (0+str_replace(",", "", $n)); // is this a number? if (!is_numeric($n)) return false; // now filter it; if ($n > 1000000000000) return round(($n/1000000000000), 2).' trillion'; elseif

Input number validation - Restrict to enter only numbers or digits, int & float both

血红的双手。 提交于 2019-11-27 13:47:16
How to restrict the input field to enter only numbers/digits int and float both. Sometimes we need to allow both integer as well as float value for fields like amount, so in that case the validation is required. There are no of solutions available but they are of large size code. So need a short but effective code. <p> Input box that accepts only valid int and float values.</p> <input class="number-only" type=text /> No need for the long code for number input restriction just try this code. It also accepts valid int & float both values. Javascript Approach onload =function(){ var ele =

VB.net Need Text Box to Only Accept Numbers

狂风中的少年 提交于 2019-11-27 13:32:12
I'm fairly new to VB.net (self taught) and was just wondering if someone out there could help me out with some code. I'm not trying to do anything too involved, just have a TextBox that accepts a numeric value from 1 to 10. I don't want it to accept a string or any number above 10. If someone types a word or character an error message will appear, telling him to enter a valid number. This is what I have; obviously it's not great as I am having problems. Thanks again to anyone who can help. If TxtBox.Text > 10 Then MessageBox.Show("Please Enter a Number from 1 to 10") TxtBox.Focus() ElseIf

Simplest way of getting the number of decimals in a number in JavaScript [duplicate]

落爺英雄遲暮 提交于 2019-11-27 13:31:28
问题 This question already has an answer here: Is there a reliable way in JavaScript to obtain the number of decimal places of an arbitrary number? 7 answers Is there a better way of figuring out the number of decimals on a number than in my example? var nbr = 37.435.45; var decimals = (nbr!=Math.floor(nbr))?(nbr.toString()).split('.')[1].length:0; By better I mean faster to execute and/or using a native JavaScript function, ie. something like nbr.getDecimals(). Thanks in advance! EDIT: After

How to format a number 1000 as “1 000”

一世执手 提交于 2019-11-27 12:47:34
问题 I need a way to format numbers. I stored some numbers in my DB table, e.g. 12500 , and would like to print them in this format 12 500 (so there is a space every 3 digits). Is there an elegant way to do this? 回答1: see: http://www.justskins.com/forums/format-number-with-comma-37369.html there is no built in way to it ( unless you using Rails, ActiveSupport Does have methods to do this) but you can use a Regex like formatted_n = n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse 回答2: Activesupport

php: number only hash?

落花浮王杯 提交于 2019-11-27 12:36:58
In php is there a way to give a unique hash from a string, but that the hash was made up from numbers only? example: return md5(234); // returns 098f6bcd4621d373cade4e832627b4f6 but I need return numhash(234); // returns 00978902923102372190 (20 numbers only) the problem here is that I want the hashing to be short. edit: OK let me explain the back story here. I have a site that has a ID for every registered person, also I need a ID for the person to use and exchange (hence it can't be too long), so far the ID numbering has been 00001, 00002, 00003 etc... this makes some people look more

XSL - rounding/format-number problem

冷暖自知 提交于 2019-11-27 12:23:29
I'm trying to get the value of a number to 2 dec places from my xml. XML: <Quantity>0.0050</Quantity> XSL: <xsl:value-of select="format-number($quantity, '####0.00')" /> However XSL seems to have a problem with this value and outputs 0.00 in one area of the page and 0.01 in the other. Of course in this situation it is favourable to have 0.01 output in all areas. Another area has the value 4.221 yet the XSL is outputting 4.23 . I do realise that format-number as a method converts a number to a string. Not sure how to fix this. EDIT: Ok after a bit of mucking around i found that this works: <xsl

Non-repetitive random number in numpy

∥☆過路亽.° 提交于 2019-11-27 12:00:50
My question is: How can I generate non-repetitive random numbers in numpy? list = np.random.random_integers(20,size=(10)) If you don't insist on using NumPy, you can use random.sample() from the standard library: print random.sample(range(20), 10) With NumPy, you will have to use numpy.random.shuffle() and slicing: a = numpy.arange(20) numpy.random.shuffle(a) print a[:10] strnam I think numpy.random.sample doesn't work right, now. This is my way: import numpy as np np.random.choice(range(20), 10, replace=False) You can get this by sorting as well: random_numbers = np.random.random([num_samples