当前位置: 首页>>代码示例>>Golang>>正文


Golang format.FormatFloat函数代码示例

本文整理汇总了Golang中go2o/src/core/infrastructure/format.FormatFloat函数的典型用法代码示例。如果您正苦于以下问题:Golang FormatFloat函数的具体用法?Golang FormatFloat怎么用?Golang FormatFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FormatFloat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetList

func (this *listC) GetList(ctx *web.Context) {
	r, w := ctx.Request, ctx.ResponseWriter
	p := this.GetPartner(ctx)

	const getNum int = -1 //-1表示全部
	categoryId, _ := strconv.Atoi(r.URL.Query().Get("cid"))
	items := dps.SaleService.GetOnShelvesGoodsByCategoryId(p.Id, categoryId, getNum)
	if len(items) == 0 {
		w.Write([]byte(`无商品`))
		return
	}
	buf := bytes.NewBufferString("<ul>")

	for _, v := range items {

		buf.WriteString(fmt.Sprintf(`
			<li>
				<div class="gs_goodss">
                        <img src="%s" alt="%s"/>
                        <h3 class="name">%s%s</h3>
                        <span class="srice">原价:¥%s</span>
                        <span class="sprice">优惠价:¥%s</span>
                        <a href="javascript:cart.add(%d,1);" class="add">&nbsp;</a>
                </div>
             </li>
		`, format.GetGoodsImageUrl(v.Image), v.Name, v.Name, v.SmallTitle, format.FormatFloat(v.Price),
			format.FormatFloat(v.SalePrice),
			v.Id))
	}
	buf.WriteString("</ul>")
	w.Write(buf.Bytes())
}
开发者ID:honj51,项目名称:go2o,代码行数:32,代码来源:list_c.go

示例2: List_Index

// 商品列表
func (this *ListC) List_Index(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		p := this.BaseC.GetPartner(ctx)

		const size int = 20 //-1表示全部

		idArr := this.getIdArray(r.URL.Path)
		page, _ := strconv.Atoi(r.FormValue("page"))
		if page < 1 {
			page = 1
		}
		categoryId := idArr[len(idArr)-1]
		cat := dps.SaleService.GetCategory(p.Id, categoryId)

		total, items := dps.SaleService.GetPagedOnShelvesGoods(p.Id, categoryId, (page-1)*size, page*size)
		var pagerHtml string
		if total > size {
			pager := pager.NewUrlPager(pager.TotalPage(total, size), page, pager.GetterDefaultPager)
			pager.RecordCount = total
			pagerHtml = pager.PagerString()
		}

		buf := bytes.NewBufferString("")

		if len(items) == 0 {
			buf.WriteString("<div class=\"no_goods\">没有找到商品!</div>")
		} else {
			for i, v := range items {
				buf.WriteString(fmt.Sprintf(`
				<div class="item item-i%d">
					<div class="block">
						<a href="/item-%d.htm" class="goods-link">
							<img class="goods-img" src="%s" alt="%s"/>
							<h3 class="name">%s</h3>
							<span class="sale-price">¥%s</span>
							<span class="market-price"><del>¥%s</del></span>
						</a>
					</div>
                    <div class="clear-fix"></div>
                </div>
		`, i%2, v.GoodsId, format.GetGoodsImageUrl(v.Image),
					v.Name, v.Name, format.FormatFloat(v.SalePrice),
					format.FormatFloat(v.Price)))
			}
		}

		this.BaseC.ExecuteTemplate(ctx, gof.TemplateDataMap{
			"cat":   cat,
			"items": template.HTML(buf.Bytes()),
			"pager": template.HTML(pagerHtml),
		},
			"views/shop/ols/{device}/list.html",
			"views/shop/ols/{device}/inc/header.html",
			"views/shop/ols/{device}/inc/footer.html")
	}
}
开发者ID:kevinhuo88888,项目名称:go2o,代码行数:58,代码来源:list_c.go

示例3: GoodsView

// 商品详情
func (this *ListC) GoodsView(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		p := this.BaseC.GetPartner(ctx)
		path := r.URL.Path
		goodsId, _ := strconv.Atoi(path[strings.LastIndex(path, "-")+1 : strings.Index(path, ".")])

		m := this.BaseC.GetMember(ctx)
		var level int = 0
		if m != nil {
			level = m.Level
		}
		goods, proMap := dps.SaleService.GetGoodsDetails(p.Id, goodsId, level)
		goods.Image = format.GetGoodsImageUrl(goods.Image)

		// 促销价 & 销售价
		var promPrice string
		var salePrice string

		if goods.PromPrice < goods.SalePrice {
			promPrice = fmt.Sprintf(`<span class="prom-price">¥<b>%s</b></span>`, format.FormatFloat(goods.PromPrice))
			salePrice = fmt.Sprintf("<del>¥%s</del>", format.FormatFloat(goods.SalePrice))
		} else {
			salePrice = "¥" + format.FormatFloat(goods.SalePrice)
		}

		// 促销信息
		var promDescribe string
		var promCls string = "hidden"
		if len(proMap) != 0 {
			promCls = ""
			buf := bytes.NewBufferString("")
			var i int = 0
			for k, v := range proMap {
				i++
				buf.WriteString(fmt.Sprintf(`<div class="prom-box prom%d">
					<span class="bg_txt red">%s</span>:<span class="describe">%s</span></div>`, i, k, v))
			}
			promDescribe = buf.String()
		}

		this.BaseC.ExecuteTemplate(ctx, gof.TemplateDataMap{
			"goods":         goods,
			"promap":        proMap,
			"prom_price":    template.HTML(promPrice),
			"sale_price":    template.HTML(salePrice),
			"prom_describe": template.HTML(promDescribe),
			"prom_cls":      promCls,
		},
			"views/shop/ols/{device}/goods.html",
			"views/shop/ols/{device}/inc/header.html",
			"views/shop/ols/{device}/inc/footer.html")
	}
}
开发者ID:zoe527,项目名称:go2o,代码行数:55,代码来源:list_c.go

示例4: Transfer_f2m

// 转换活动金到提现账户
func (this *accountC) Transfer_f2m(ctx *web.Context) {
	p := this.GetPartner(ctx)
	conf := this.GetSiteConf(p.Id)
	saleConf := dps.PartnerService.GetSaleConf(p.Id)
	m := this.GetMember(ctx)
	acc := dps.MemberService.GetAccount(m.Id)

	var commissionStr string
	if saleConf.FlowConvertCsn == 0 {
		commissionStr = "不收取手续费"
	} else {
		commissionStr = fmt.Sprintf("收取<i>%s%s</i>手续费",
			format.FormatFloat(saleConf.FlowConvertCsn*100), "%")
	}

	this.ExecuteTemplate(ctx, gof.TemplateDataMap{
		"conf":           conf,
		"partner":        p,
		"member":         m,
		"account":        acc,
		"commissionStr":  template.HTML(commissionStr),
		"flowAlias":      variable.AliasFlowAccount,
		"cns":            saleConf.TransCsn,
		"notSetTradePwd": len(m.TradePwd) == 0,
	}, "views/ucenter/{device}/account/transfer_f2m.html",
		"views/ucenter/{device}/inc/header.html",
		"views/ucenter/{device}/inc/menu.html",
		"views/ucenter/{device}/inc/footer.html")
}
开发者ID:zoe527,项目名称:go2o,代码行数:30,代码来源:account_c.go

示例5: backCashForMember

func backCashForMember(m member.IMember, order *shopping.ValueOrder, fee int, refName string) error {
	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	bFee := float32(fee)
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		//给自己返现
		icLog := &member.IncomeLog{
			MemberId:   m.GetAggregateRootId(),
			OrderId:    order.Id,
			Type:       "backcash",
			Fee:        float32(fee),
			Log:        fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s", format.FormatFloat(bFee), order.OrderNo, refName),
			State:      1,
			RecordTime: acv.UpdateTime,
		}
		err = m.SaveIncomeLog(icLog)
	}
	return err
}
开发者ID:henrylee2cn,项目名称:go2o,代码行数:25,代码来源:cash_back.go

示例6: Apply_cash

// 提现申请
func (this *accountC) Apply_cash(ctx *web.Context) {
	p := this.GetPartner(ctx)
	conf := this.GetSiteConf(p.Id)
	m := this.GetMember(ctx)
	acc := dps.MemberService.GetAccount(m.Id)
	saleConf := dps.PartnerService.GetSaleConf(p.Id)

	var latestInfo string = dps.MemberService.GetLatestApplyCashText(m.Id)
	if len(latestInfo) != 0 {
		latestInfo = "<div class=\"info\">" + latestInfo + "</div>"
	}

	var maxApplyAmount int
	if acc.PresentBalance < float32(minAmount) {
		maxApplyAmount = 0
	} else {
		maxApplyAmount = int(acc.PresentBalance)
	}

	var commissionStr string
	if saleConf.ApplyCsn == 0 {
		commissionStr = "不收取手续费"
	} else {
		commissionStr = fmt.Sprintf("收取<i>%s%s</i>手续费",
			format.FormatFloat(saleConf.ApplyCsn*100), "%")
	}

	this.ExecuteTemplate(ctx, gof.TemplateDataMap{
		"conf":           conf,
		"partner":        p,
		"member":         m,
		"minAmount":      format.FormatFloat(float32(minAmount)),
		"maxApplyAmount": maxApplyAmount,
		"account":        acc,
		"latestInfo":     template.HTML(latestInfo),
		"commissionStr":  template.HTML(commissionStr),
		"presentAlias":   variable.AliasFlowAccount,
		"cns":            saleConf.ApplyCsn,
		"notSetTradePwd": len(m.TradePwd) == 0,
	}, "views/ucenter/{device}/account/apply_cash.html",
		"views/ucenter/{device}/inc/header.html",
		"views/ucenter/{device}/inc/menu.html",
		"views/ucenter/{device}/inc/footer.html")
}
开发者ID:zoe527,项目名称:go2o,代码行数:45,代码来源:account_c.go

示例7: GetGoodsDetails

// 获取商品详情
func (this *saleService) GetGoodsDetails(partnerId, goodsId, mLevel int) (*valueobject.Goods, map[string]string) {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoods(goodsId)
	gv := goods.GetPackedValue()
	proMap := goods.GetPromotionDescribe()
	if b, price := goods.GetLevelPrice(mLevel); b {
		gv.PromPrice = price
		proMap["会员专享"] = fmt.Sprintf("会员优惠,仅需<b>¥%s</b>",
			format.FormatFloat(price))
	}
	return gv, proMap
}
开发者ID:tonycoming,项目名称:go2o,代码行数:13,代码来源:sale_service.go

示例8: GetList

func (this *listC) GetList(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	p := this.GetPartner(ctx)
	pa := this.GetPartnerApi(ctx)

	const getNum int = -1 //-1表示全部
	categoryId, err := strconv.Atoi(r.URL.Query().Get("cid"))
	if err != nil {
		w.Write([]byte(`{"error":"yes"}`))
		return
	}
	items, err := goclient.Partner.GetItems(p.Id, pa.ApiSecret, categoryId, getNum)
	if err != nil {
		w.Write([]byte(`{"error":"` + err.Error() + `"}`))
		return
	}
	buf := bytes.NewBufferString("<ul>")

	for _, v := range items {

		buf.WriteString(fmt.Sprintf(`
			<li>
				<div class="gs_goodss">
                        <img src="%s" alt="%s"/>
                        <h3 class="name">%s%s</h3>
                        <span class="srice">原价:¥%s</span>
                        <span class="sprice">优惠价:¥%s</span>
                        <a href="javascript:cart.add(%d,1);" class="add">&nbsp;</a>
                </div>
             </li>
		`, format.GetGoodsImageUrl(v.Image), v.Name, v.Name, v.SmallTitle, format.FormatFloat(v.Price),
			format.FormatFloat(v.SalePrice),
			v.Id))
	}
	buf.WriteString("</ul>")
	w.Write(buf.Bytes())
}
开发者ID:sunxboy,项目名称:go2o,代码行数:37,代码来源:list_c.go

示例9: backCashForMember

func backCashForMember(m member.IMember, order *shopping.ValueOrder,
	fee int, refName string) error {
	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	bFee := float32(fee)
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		tit := fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s",
			format.FormatFloat(bFee), order.OrderNo, refName)
		err = acc.PresentBalance(tit, order.OrderNo, float32(fee))
	}
	return err
}
开发者ID:zoe527,项目名称:go2o,代码行数:18,代码来源:cash_back.go

示例10: LvPrice

func (this *goodsC) LvPrice(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	//todo: should be goodsId
	itemId, _ := strconv.Atoi(ctx.Request.URL.Query().Get("item_id"))
	goods := dps.SaleService.GetGoodsBySku(partnerId, itemId, 0)
	lvs := dps.PartnerService.GetMemberLevels(partnerId)
	var prices []*sale.MemberPrice = dps.SaleService.GetGoodsLevelPrices(partnerId, goods.GoodsId)

	var buf *bytes.Buffer = bytes.NewBufferString("")

	var fmtFunc = func(level int, levelName string, id int, price float32, enabled int) {
		buf.WriteString(fmt.Sprintf(`
		<tr>
                <td><input type="hidden" field="Id_%d" value="%d"/>
                    %s</td>
                <td align="center"><input type="number" field="Price_%d" value="%s"/></td>
                <td align="center"><input type="checkbox" field="Enabled_%d" %s/></td>
            </tr>
		`, level, id, levelName, level, format.FormatFloat(price), level,
			gfmt.BoolString(enabled == 1, "checked=\"checked\"", "")))
	}

	var b bool
	for _, v := range lvs {
		b = false
		for _, v1 := range prices {
			if v.Value == v1.Level {
				fmtFunc(v.Value, v.Name, v1.Id, v1.Price, v1.Enabled)
				b = true
				break
			}
		}
		if !b {
			fmtFunc(v.Value, v.Name, 0, goods.SalePrice, 0)
		}
	}

	ctx.App.Template().Execute(ctx.Response, gof.TemplateDataMap{
		"goods":   goods,
		"setHtml": template.HTML(buf.String()),
	}, "views/partner/goods/level_price.html")
}
开发者ID:zoe527,项目名称:go2o,代码行数:42,代码来源:goods_c.go

示例11: Edit_cb

func (this *promC) Edit_cb(ctx *web.Context) {
	form := ctx.Request.URL.Query()
	id, _ := strconv.Atoi(form.Get("id"))
	e, e2 := dps.PromService.GetPromotion(id)

	js, _ := json.Marshal(e)
	js2, _ := json.Marshal(e2)

	var goodsInfo string
	goods := dps.SaleService.GetValueGoods(this.GetPartnerId(ctx), e.GoodsId)
	goodsInfo = fmt.Sprintf("%s<span>(销售价:%s)</span>", goods.Name, format.FormatFloat(goods.SalePrice))

	ctx.App.Template().Execute(ctx.Response,
		gof.TemplateDataMap{
			"entity":     template.JS(js),
			"entity2":    template.JS(js2),
			"goods_info": template.HTML(goodsInfo),
			"goods_cls":  "",
		},
		"views/partner/promotion/cash_back.html")
}
开发者ID:henrylee2cn,项目名称:go2o,代码行数:21,代码来源:prom_c.go

示例12: GetLatestApplyCashText

// 获取最近的提现描述
func (this *memberService) GetLatestApplyCashText(memberId int) string {
	var latestInfo string
	latestApplyInfo := this.GetLatestApplyCash(memberId)
	if latestApplyInfo != nil {
		var sText string
		switch latestApplyInfo.State {
		case 0:
			sText = "已申请"
		case 1:
			sText = "已审核,等待打款"
		case 2:
			sText = "被退回"
		case 3:
			sText = "已完成"
		}
		latestInfo = fmt.Sprintf(`<b>最近提现:</b>%s&nbsp;申请提现%s ,状态:<span class="status">%s</span>。`,
			time.Unix(latestApplyInfo.CreateTime, 0).Format("2006-01-02 15:04"),
			format.FormatFloat(latestApplyInfo.Amount),
			sText)
	}
	return latestInfo
}
开发者ID:zoe527,项目名称:go2o,代码行数:23,代码来源:member_service.go

示例13: GetLatestApplyCashText

// 获取最近的提现描述
func (this *memberService) GetLatestApplyCashText(memberId int) string {
	var latestInfo string
	latestApplyInfo := this.GetLatestApplyCash(memberId)
	if latestApplyInfo != nil {
		var sText string
		switch latestApplyInfo.State {
		case 0:
			sText = "已提交"
		case 1:
			sText = "已审核"
		case 2:
			sText = "被退回"
		case 3:
			sText = "已完成"
		}
		latestInfo = fmt.Sprintf("您于%s申请提现%s,%s。",
			time.Unix(latestApplyInfo.CreateTime, 0).Format("2006-01-02 15:04:05"),
			format.FormatFloat(latestApplyInfo.Amount),
			sText)
	}
	return latestInfo
}
开发者ID:henrylee2cn,项目名称:go2o,代码行数:23,代码来源:member_service.go

示例14: Apply_cash_post

func (this *accountC) Apply_cash_post(ctx *web.Context) {
	var msg gof.Message
	var err error
	ctx.Request.ParseForm()
	partnerId := this.GetPartner(ctx).Id
	amount, _ := strconv.ParseFloat(ctx.Request.FormValue("Amount"), 32)
	tradePwd := ctx.Request.FormValue("TradePwd")
	if amount < minAmount {
		err = errors.New(fmt.Sprintf("必须达到最低提现金额:%s元",
			format.FormatFloat(float32(minAmount))))
	} else {
		m := this.GetMember(ctx)
		err = dps.MemberService.SubmitApplyCash(partnerId, m.Id, tradePwd, member.TypeApplyCashToBank, float32(amount))
	}

	if err != nil {
		msg.Message = err.Error()
	} else {
		msg.Result = true
	}
	ctx.Response.JsonOutput(msg)
}
开发者ID:henrylee2cn,项目名称:go2o,代码行数:22,代码来源:account_c.go

示例15: Apply_cash_post

func (this *accountC) Apply_cash_post(ctx *web.Context) {
	var msg gof.Message
	var err error
	ctx.Request.ParseForm()
	partnerId := this.GetPartner(ctx).Id
	amount, _ := strconv.ParseFloat(ctx.Request.FormValue("Amount"), 32)
	tradePwd := ctx.Request.FormValue("TradePwd")
	memberId := this.GetMember(ctx).Id
	saleConf := dps.PartnerService.GetSaleConf(partnerId)
	bank := dps.MemberService.GetBank(memberId)

	if bank == nil || len(bank.Account) == 0 || len(bank.AccountName) == 0 ||
		len(bank.Network) == 0 {
		err = errors.New("请先设置收款银行信息")
		goto toErr
	}

	if _, err = dps.MemberService.VerifyTradePwd(memberId, tradePwd); err != nil {
		goto toErr
	}

	if amount < minAmount {
		err = errors.New(fmt.Sprintf("必须达到最低提现金额:%s元",
			format.FormatFloat(float32(minAmount))))
	} else {
		m := this.GetMember(ctx)
		err = dps.MemberService.SubmitApplyPresentBalance(partnerId, m.Id,
			member.TypeApplyCashToBank, float32(amount), saleConf.ApplyCsn)
	}

toErr:
	if err != nil {
		msg.Message = err.Error()
	} else {
		msg.Result = true
	}
	ctx.Response.JsonOutput(msg)
}
开发者ID:zoe527,项目名称:go2o,代码行数:38,代码来源:account_c.go


注:本文中的go2o/src/core/infrastructure/format.FormatFloat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。