Aristarkos/notebooks/typecast.jl

64 lines
1.9 KiB
Julia

### A Pluto.jl notebook ###
# v0.12.4
using Markdown
using InteractiveUtils
# ╔═╡ 347f99b2-18be-11eb-2ee8-f92ec1a3be6f
Σ = [1 2 3; 4 5 6]
# ╔═╡ c10eced4-1774-11eb-151a-21f1a1c60225
Σ_float = convert(Matrix{Float32}, Σ)
# ╔═╡ ee1b09c8-196e-11eb-2362-37b9901ade27
Σ_float[1, 2] = 93
# ╔═╡ fc1de1da-196e-11eb-33cd-23c342307d56
# the above cell is equal to this:
Σ_float[1, 2] = convert(Float32, 93)
# convert is called implicitly in other context: see the manual
# custom behavior for convert is possible
# ╔═╡ 2d3efb3a-1971-11eb-3079-f148a705b630
Base.float(Σ) # helper function, but returns only Float64
# ╔═╡ b193ef8c-196f-11eb-08d3-f9ecd7a90907
Σ_float
# ╔═╡ c9e251a2-1970-11eb-2096-a9bdd1c39478
# convert string to numerical type
parse(Int, "3")
# ╔═╡ 128f4e3e-1971-11eb-3d6e-1f346839cf41
parse(Float64, "3.5")
# ╔═╡ 1b4e8558-1971-11eb-3486-63f5b0ee6333
# convert integer to string in the specified base
Base.string(14, base = 16)
# ╔═╡ ec19bf68-1971-11eb-3bbd-21a42ac455d4
# convert multiple arguments to a string (not just integers)
Base.string("Hello: ", 1.3, ' ', [1 2])
# ╔═╡ 0ebb8178-1972-11eb-32d4-f144eeb29db1
# string concatenation
"Hello " * " World!"
# ╔═╡ 544ef468-1972-11eb-2b5b-f5e9323069b8
# gives the string representation of a value using the show() function (which prints to IO)
repr([1 2; 3 4])
# ╔═╡ Cell order:
# ╠═347f99b2-18be-11eb-2ee8-f92ec1a3be6f
# ╠═c10eced4-1774-11eb-151a-21f1a1c60225
# ╠═ee1b09c8-196e-11eb-2362-37b9901ade27
# ╠═fc1de1da-196e-11eb-33cd-23c342307d56
# ╠═2d3efb3a-1971-11eb-3079-f148a705b630
# ╠═b193ef8c-196f-11eb-08d3-f9ecd7a90907
# ╠═c9e251a2-1970-11eb-2096-a9bdd1c39478
# ╠═128f4e3e-1971-11eb-3d6e-1f346839cf41
# ╠═1b4e8558-1971-11eb-3486-63f5b0ee6333
# ╠═ec19bf68-1971-11eb-3bbd-21a42ac455d4
# ╠═0ebb8178-1972-11eb-32d4-f144eeb29db1
# ╠═544ef468-1972-11eb-2b5b-f5e9323069b8