www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to find how many places from left the dot appears in a

reply rempas <rempas tutanota.com> writes:
Let's say that I have the following float/double: 137.837

How can I find how many places from left the dot appears? So in 
this example I want to take either three or four (depending on 
how you think it). Does anyone knows how I can do that and can 
explain it to me?
Dec 30 2021
parent reply afg45 <afg45 afg45.ck> writes:
On Thursday, 30 December 2021 at 09:03:58 UTC, rempas wrote:
 Let's say that I have the following float/double: 137.837

 How can I find how many places from left the dot appears? So in 
 this example I want to take either three or four (depending on 
 how you think it). Does anyone knows how I can do that and can 
 explain it to me?
See the https://en.wikipedia.org/wiki/Common_logarithm fpr the explanations. ``` import std.stdio, std.math; void main(string[] args) { alias numDigits = (f) => log10(f + 0.5).ceil(); } ```
Dec 30 2021
parent rempas <rempas tutanota.com> writes:
On Thursday, 30 December 2021 at 11:17:39 UTC, afg45 wrote:
 See the https://en.wikipedia.org/wiki/Common_logarithm fpr the 
 explanations.

 ```
 import std.stdio, std.math;

 void main(string[] args)
 {
     alias numDigits = (f) => log10(f + 0.5).ceil();
 }
 ```
Thanks a lot! However, I used the "log10" function from "libm" because I will need to not use Phobos anyway
Dec 30 2021