首页 > 其他分享 >go语言math包及标准输入

go语言math包及标准输入

时间:2023-05-30 11:55:43浏览次数:32  
标签:包及 fmt Floor Println 2.5 go Round math

数值处理

取整

fmt.Println(1/2, 3/2, 5/2)
fmt.Println(-1/2, -3/2, -5/2)
fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fmt.Println(math.Ceil(2.01), math.Ceil(2.5), math.Ceil(2.8))
fmt.Println(math.Ceil(-2.01), math.Ceil(-2.5), math.Ceil(-2.8))
fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fmt.Println(math.Floor(2.01), math.Floor(2.5), math.Floor(2.8))
fmt.Println(math.Floor(-2.01), math.Floor(-2.5), math.Floor(-2.8))
fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fmt.Println(math.Round(2.01), math.Round(2.5), math.Round(2.8))
fmt.Println(math.Round(-2.01), math.Round(-2.5), math.Round(-2.8))
fmt.Println(math.Round(0.5), math.Round(1.5), math.Round(2.5), 
math.Round(3.5))

/ 整数除法,截取整数部分

math.Ceil 向上取整

math.Floor 向下取整

math.Round 四舍五入

 其它数值处理

fmt.Println(math.Abs(-2.7)) // 绝对值
fmt.Println(math.E, math.Pi) // 常数
fmt.Println(math.MaxInt16, math.MinInt16) // 常量,极值
fmt.Println(math.Log10(100), math.Log2(8)) // 对数
fmt.Println(math.Max(1, 2), math.Min(-2, 3)) // 最大值、最小值
fmt.Println(math.Pow(2, 3), math.Pow10(3)) // 幂
fmt.Println(math.Mod(5, 2), 5%2) // 取模
fmt.Println(math.Sqrt(2), math.Sqrt(3), math.Pow(2, 0.5)) // 开方

 

标签:包及,fmt,Floor,Println,2.5,go,Round,math
From: https://www.cnblogs.com/caibao666/p/17442858.html

相关文章

  • django pluralize Filter
    Ifthevalueisnot1,'1',oranobjectoflength1,the pluralize filteroutputsan“s”orthevalueofthe suffix argumentifoneisused.Variableclasses={'Python':['IntroPython','AdvancedPython&......
  • MongoDB学习笔记:配置文件
    本文更新于2023-05-11。使用MongoDB6.0.4。官方文档:https://www.mongodb.com/docs/manual/reference/configuration-options/Linux下配置文件为/etc/mongod.conf。#后面的内容作为注释忽略。大多数参数与mongod的命令行参数对应,如命令行参数为不需指定值的开关则设置为true或f......
  • Go语言学习之路
    【阶段1Go语言基础】Day01变量、字符串、运算符Day02Go语言流程控制、数组、切片、切片原理、map、Day03函数基础、错误处理、包管理Day04常用内置包Day05结构体Day06文件I/O操作Day07接口Day08并发编程Day09网络编程Day10webrpc爬虫模板语法【阶段2Go......
  • djangorestframework-simplejwt使用
    djangorestframework-simplejwt环境Python(3.7,3.8,3.9,3.10)Django(2.2,3.1,3.2,4.0)DjangoRESTFramework(3.10,3.11,3.12,3.13)安装普通安装pip3installdjangorestframework-jwt加密安装pipinstalldjangorestframework-simplejwt[crypto]#建议在......
  • 批量创建google浏览器快捷方式
    importosfromwin32comimportclientdefcreate_chrome(name,num):chrome_path="C:\ProgramFiles\Google\Chrome\Application\chrome.exe"user_dir_data=f"D:\data\google\Chrome{num}"#定义快捷方式的目标路径和名称,快捷方式的路径#short......
  • Kubernetes GoRoutineMap工具包代码详解
    1、概述GoRoutineMap定义了一种类型,可以运行具有名称的goroutine并跟踪它们的状态。它防止创建具有相同名称的多个goroutine,并且在上一个具有该名称的goroutine完成后的一段退避时间内可能阻止重新创建goroutine。使用GoRoutineMap场景:使用协程的方式运行函数逻辑,如果函......
  • GoldWave是什么软件?goldwave怎么设置中文
    本文参考资料:https://blog.csdn.net/weixin_55412152/article/details/130935207GoldWave6.68是一款专业的,集录音、编辑于一身的音频编辑软件,不仅提供了出色的编辑功能,还提供了丰富的音效选项,可进行混音、剪辑、音效制作等操作,是一款实用、界面友好的音频编辑软件。GoldWave编辑音......
  • 1006.Django项目用户功能之QQ登录
    一、PIL库PIL:Python图像库PIL(PythonImageLibrary)是python的第三方图像处理库,但是由于其强大的功能与众多的使用人数,几乎已经被认为是python官方图像处理库了。环境中下载:pipinstallpillow图像验证码1.初始化:字符长度,宽度,高度,字符大小;2.随机产生字符:26个大小写字母和......
  • Spider理论系列--MongoDB(二)
    六、INSERT使用insert db.集合名.insert(文档)#如果是添加数据建议使用insert插入多条数据: db.集合名.insert([文档])#注意一定要加[]否则可能只会把第一条文档插入进去db.user.insert({'name':'lisi','age':20})db.user.insert([{'name':'lisi','age':......
  • 如何将数据从MySQL/MongoDB中迁移至云开发数据库
    本篇文章从MySQL、MongoDB迁移到云开发数据库,其他数据库迁移也都大同小异~迁移大致分为以下几步?:从MySQL、MongoDB将数据库导出为JSON或CSV格式创建一个云开发环境到云开发数据库新建一个集合在集合内导入JSON或CSV格式文件Mysql迁移到云开发数据库为了方便,我们使用Na......