Answers.Body: <h2>For recent versions of AE (AE 2019+)</h2>
  
  <p>you can use the javascript <code>Intl.NumberFormat</code> object, which does all the formatting for you without any tedious string munging and regex and all that carry-on.</p>
  
  <pre class="lang-js prettyprint-override"><code>var sliderVal = thisComp.layer("controller).effect("206")("Slider");
  Intl.NumberFormat('en-AU', {minimumFractionDigits: 1, maximumFractionDigits: 1}).format(sliderVal/10)
  </code></pre>
  
  <p>the <code>en-EN</code> part is the locale string, and is your preferred locale, in other words, your culturally specific way of displaying numbers (<code>en-AU</code> is for Australia, and uses <code>.</code> for the decimal separator and <code>,</code> for the thousands separator). This makes it <em>super</em> easy to format, because it handles things like thousands separators, currency symbols and even what characters you want. You want it in Chinese decimals? Sure use <code>'zh-Hans-CN-u-nu-hanidec'</code> and it will look like</p>
  
  <p>一,六二九.二</p>
  
  <p>The second parameter is the options, and here we get to specify things like <code>minimumFractionDigits</code> and <code>maximumFractionDigits</code>. You can also zero-pad the number with <code>minimumIntegerDigits</code>, so a zero-padded number with 5 digits and one decimal place would be specified thus:</p>
  
  <pre class="lang-js prettyprint-override"><code>Intl.NumberFormat('en-AU', {minimumIntegerDigits: 5, minimumFractionDigits: 1, maximumFractionDigits: 1}).format(theNumberToFormat); 
  </code></pre>
  
  <p>Read the docs <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat" rel="nofollow noreferrer">here</a></strong></p>
  
  <p>It's worth noting that the usual suspect for number formatting <code>someNumber.toLocaleString()</code>, which is much simpler, doesn't work for what you want. For some reason in AE's implementation of JS it always returns two digits and adding <code>maximumFractionDigits</code> as an option doesn't work. </p>
  
  <h2>For earlier versions of AE</h2>
  
  <p>Here's how to get the 1 decimal place after the number:</p>
  
  <pre class="lang-js prettyprint-override"><code>var n = Math.round(theNumberToFormat *10)/10;
  (n % 1 === 0)? '' + n + ".0": n
  </code></pre>
  
  <p>The first line rounds off any digits after the first decimal, the second is for when the number is an integer (when <code>n % 1</code> is 0, <code>%</code> being the modulus operator which returns the remainder of the first number divided by the second), which would normally display with no decimal. If it is, it treats the resulting number as a string and adds <code>'.0'</code> to the end of it. If you want thousands separators you need to do some further trickery, that's a common JS question on SO, e.g. <a href="https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript">here</a>.</p>
  
  <pre><code>var n = Math.round(theNumberToFormat *10)/10;
  n = (n % 1 === 0)? '' + n + ".0": n
  n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  </code></pre>
  
  <p>The last line is fancy regex voodo, I don't know exactly how it works, it's got something to do with lookaheads and whatnot. But it works.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T05:52:47.233Z
Answers.Text: I'm using Ae 2015 version
Answers.UserDisplayName: user152435
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T06:13:06.067Z
Answers.Text: Have you tried it? There were a lot of undocumented goodies in earlier versions, you never know…
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T07:16:11.323Z
Answers.Text: Sorry I'm very new to slider expressions, could you please tell me, that how I use that second line with that thisComp.layer things?
Answers.UserDisplayName: user152435
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T07:17:20.577Z
Answers.Text: Ps. Ah I got the result...!! thank you dude!!
Answers.UserDisplayName: user152435
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T17:13:04.220Z
Answers.Text: Replace theNumberToFormat with the number you want to format. So if you use the first line of the other expression, it would be n
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T17:15:42.967Z
Answers.Text: PS, don't thank me, mash that tick button. It helps others find the answer too
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-15T05:25:45.727Z
Answers.Text: Done, and thank you agian :-p
Answers.UserDisplayName: user152435
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-12T05:36:30.337Z
Answers.LastActivityDate: 2019-11-12T06:55:54.373Z
Answers.LastEditDate: 2019-11-12T06:55:54.373Z
Answers.UserDisplayName: stib
Body: <p>I have a slider-controlled source text which I try to sync with the corresponding graph bar. What I need is, to display one decimal point after the value of the slider is divided by 10. That is, if the slider's value is 80, I want to display the value, 8.0 on the source text. Of course I need the zero, after the 8, which is a whole number.</p>
  
  <p><a href="https://i.sstatic.net/ZxTHp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZxTHp.png" alt="enter image description here"></a></p>
  
Tags: <after-effects><after-effects-expressions>
Title: Display one decimal point after a whole number after divided by 10
UserDisplayName: user152435
ThreadText: # Display one decimal point after a whole number after divided by 10
  
  (Asked by: username_0 on 2019-11-12)
  
  I have a slider-controlled source text which I try to sync with the corresponding graph bar. What I need is, to display one decimal point after the value of the slider is divided by 10. That is, if the slider's value is 80, I want to display the value, 8.0 on the source text. Of course I need the zero, after the 8, which is a whole number.
  
  [![enter image description here](https://i.sstatic.net/ZxTHp.png)](https://i.sstatic.net/ZxTHp.png)
  
  **Tags:** after-effects, after-effects-expressions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-12. Score: 0 | Accepted answer
  
  ## For recent versions of AE (AE 2019+)
  
  you can use the javascript `Intl.NumberFormat` object, which does all the formatting for you without any tedious string munging and regex and all that carry-on.
  
  ```js
  var sliderVal = thisComp.layer("controller).effect("206")("Slider");
  Intl.NumberFormat('en-AU', {minimumFractionDigits: 1, maximumFractionDigits: 1}).format(sliderVal/10)
  
  ```
  
  the `en-EN` part is the locale string, and is your preferred locale, in other words, your culturally specific way of displaying numbers (`en-AU` is for Australia, and uses `.` for the decimal separator and `,` for the thousands separator). This makes it *super* easy to format, because it handles things like thousands separators, currency symbols and even what characters you want. You want it in Chinese decimals? Sure use `'zh-Hans-CN-u-nu-hanidec'` and it will look like
  
  一,六二九.二
  
  The second parameter is the options, and here we get to specify things like `minimumFractionDigits` and `maximumFractionDigits`. You can also zero-pad the number with `minimumIntegerDigits`, so a zero-padded number with 5 digits and one decimal place would be specified thus:
  
  ```js
  Intl.NumberFormat('en-AU', {minimumIntegerDigits: 5, minimumFractionDigits: 1, maximumFractionDigits: 1}).format(theNumberToFormat); 
  
  ```
  
  Read the docs **[here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)**
  
  It's worth noting that the usual suspect for number formatting `someNumber.toLocaleString()`, which is much simpler, doesn't work for what you want. For some reason in AE's implementation of JS it always returns two digits and adding `maximumFractionDigits` as an option doesn't work.
  
  ## For earlier versions of AE
  
  Here's how to get the 1 decimal place after the number:
  
  ```js
  var n = Math.round(theNumberToFormat *10)/10;
  (n % 1 === 0)? '' + n + ".0": n
  
  ```
  
  The first line rounds off any digits after the first decimal, the second is for when the number is an integer (when `n % 1` is 0, `%` being the modulus operator which returns the remainder of the first number divided by the second), which would normally display with no decimal. If it is, it treats the resulting number as a string and adds `'.0'` to the end of it. If you want thousands separators you need to do some further trickery, that's a common JS question on SO, e.g. [here](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript).
  
  ```
  var n = Math.round(theNumberToFormat *10)/10;
  n = (n % 1 === 0)? '' + n + ".0": n
  n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  
  ```
  
  The last line is fancy regex voodo, I don't know exactly how it works, it's got something to do with lookaheads and whatnot. But it works.
  
  > **Comments:**
  > **username_0**: I'm using Ae 2015 version  
  > **username_1**: Have you tried it? There were a lot of undocumented goodies in earlier versions, you never know…  
  > **username_0**: Sorry I'm very new to slider expressions, could you please tell me, that how I use that second line with that thisComp.layer things?  
  > **username_0**: Ps. Ah I got the result...!! thank you dude!!  
  > **username_1**: Replace theNumberToFormat with the number you want to format. So if you use the first line of the other expression, it would be n  
  > **username_1**: PS, don't thank me, mash that tick button. It helps others find the answer too  
  > **username_0**: Done, and thank you agian :-p  
  
  ---
  
  