Git Product home page Git Product logo

Comments (4)

shepherdwind avatar shepherdwind commented on July 20, 2024

以前是没有加小数的支持。

from velocity.js.

muzi131313 avatar muzi131313 commented on July 20, 2024

@shepherdwind 现在支持小数格式化么?比如说:
15.52我想格式化成15.5这样的数值;
在网上找到的其他人的实现

#macro(oneNum $num)
    #set($string = $num+"") 
    #set($stringList = $stringUtil.split($string,"."))  
    #set($strSize = $stringList.size())  
    #if($strSize==2) 
        #set($subStr = $stringList.get(1))  
        #set($subStrSize = $subStr.length())  
        #if($subStrSize>1)  
            $stringList.get(0).$subStr.substring(0,1)  
        #else  
            $stringList.get(0).$subStr  
        #end
    #else
        $string  
    #end
#end

还有一种是$number.format('#0.0', 12.35)
这两种都需要后台配置,有没有velocity原生支持格式化小数位的?
后台不知道怎么配置。ps: 数值、日期格式化stackoverlfow: format number in velocity template

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

@muzi131313 这种问题可以单独提一个 issue 的。

原生的 velocity 是 java ,在 js 中可以拿到 js 数字对象,你可以 $number.toFixed(2) 应该就可以了

from velocity.js.

muzi131313 avatar muzi131313 commented on July 20, 2024

@shepherdwind 大神就是大神,一下子就解决了我纠结N久的问题。一直想着velocity需要后台支持,忘记咱们这个版本是支持js语法的。感谢

from velocity.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.