A one-liner, with type conversion to get an integer back:

*convert(Int64,floor(x/10^(floor(log10(x)))))*

On Saturday, October 24, 2015 at 11:40:03 AM UTC-4, Michele Zaffalon wrote:
>
> There is also the builtin 
> http://docs.julialang.org/en/latest/stdlib/numbers/#Base.digits
>
> On Sat, Oct 24, 2015 at 3:51 PM, Tamas Papp <tkp...@gmail.com 
> <javascript:>> wrote:
>
>> A trivial (but not necessarily the fastest) solution is
>>
>> function firstdigit(i,base=10)
>>     while (i >= base)
>>         i = div(i,base)
>>     end
>>     i
>> end
>>
>> Best,
>>
>> Tamas
>>
>> On Sat, Oct 24 2015, paul analyst <paul.a...@mail.com <javascript:>> 
>> wrote:
>>
>> > How to get first number from Int64
>> >
>> > julia> lista[3]
>> > 464
>> >
>> > julia> eltype(lista[3])
>> > Int64
>> >
>> > julia> length(lista[3])
>> > 1
>> >
>> > julia> lista[3][]
>> > 464
>> >
>> > julia> lista[3][1]
>> >
>> > I need the first "4"
>> > Paul
>>
>>
>

Reply via email to